1

我需要一个在向下滚动页面时粘在顶部的标题。我正在使用以下 jquery 函数

<script type="text/javascript">
google.load("jquery", "1");

function sticky_relocate() {
  var window_top = $(window).scrollTop();
  var div_top = $('#sticky-anchor').offset().top;
  if (window_top > div_top)
    $('#sticky').addClass('stick')
  else
    $('#sticky').removeClass('stick');
  }
// If you have jQuery directly, use the following line, instead
// $(function() {
// If you have jQuery via Google AJAX Libraries
google.setOnLoadCallback(function() {
  $(window).scroll(sticky_relocate);
  sticky_relocate();
  });
</script> 

但是页面中已经存在的滑块无法正常工作!请帮我解决这个问题。我$.noConflict();在功能上方添加了滑块正常工作并且粘性 div 不起作用!

并对代码进行了以下更改 // 开始关闭以防止命名空间冲突

;(function($) {

// Whatever code you want that relies on $ as the jQuery object

// End closure
})(jQuery);

滑块和粘性 div 都不起作用!

4

0 回答 0