数据库获取链接列表的平滑滚动

时间:2014-12-20 21:38:30

标签: jquery html css

我已经搜索了很多,但找不到类似我的问题。所有指定的链接都应用了平滑滚动方法。

我的网站允许用户在他们的页面上添加帖子。我想获取帖子的标题(滚动到特定的帖子)并在点击标题链接时进行平滑滚动。但问题是,我不是&# 39;知道他们提交的帖子数量,因为数据库是按用户帖子更新的。

那么,当点击相应的标题时,如何将用户链接到给定的帖子?

我找到了特定数量的链接,看起来像这样

HTML

<a id="up" href="#down">down</a>
<div class="up"></div>

<a id="down" href="#up">up</a>
<div class="down"></div> 

CSS

.up {
  width:100px;
  height: 400px;
  background-color: red;
}

.down {
  width:100px;
  height: 400px;
  background-color: yellow;
}

JQuery的

$('#up, #down').on('click', function(e){
e.preventDefault();
var target= $(this).get(0).id == 'up' ? $('#down') : $('#up');
$('html, body').stop().animate({
   scrollTop: target.offset().top
}, 1000);
});

以下是获取帖子和标题的部分。

 $sql3="SELECT * FROM news WHERE id='$idx'";
 $query3=mysqli_query($connect_dude,$sql3);
 $num_row3=mysqli_num_rows($query3);
 $posts="";
 $title_to_scroll="";
  if($num_row3>0){
   while($row3=mysqli_fetch_assoc($query3)){
     $title3=$row3["title"];
     $post3=$row3["post"];
     $date3=$row3["date"];

  $title_to_scroll.="<div id='tit'><a href='#'>$title3</a></div>";
  $posts.="<div id=\"news_post\"><div id='top'><b>Posted on  </b>$date3<h2>$title3<hr id='hrx'></h2></div><br><br><div id='post'>$post3</div></div> ";
}

然后我只在HTML部分打印

0 个答案:

没有答案
相关问题