閱讀281 返回首頁    go 阿裏雲 go 技術社區[雲棲]


簡單的 jQuery 浮動層隨窗口滾動滑動插件實例

寫了一個非常簡單的 jQuery 插件實例  浮動層隨窗口滾動滑動

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
(function($){
    $.fn.floatAutoScroll = function(){
        this.each(function(){
            var obj = $(this);
            var top = obj.css('top').replace('px', '');
            $(window).scroll(function(){
                var scrollTop = $(window).scrollTop();
                obj.stop().animate({ top:(top*1 + scrollTop*1) }, 'normal');
            });
        });
    }
})(jQuery);
$(function(){
    $('.float-container').floatAutoScroll();
});
</script>
<style type="text/css">
.main { height:1500px; }
.float-container { position:absolute; right:0; width:50px; height:50px; background-color:#960; }
.float1 { top:100px; }
.float2 { top:200px; }
.float3 { top:300px; }
</style>
</head>
      
<body>
<div ></div>
<div >浮動框1</div>
<div >浮動框2</div>
<div >浮動框3</div>
</body>
</html>


最後更新:2017-04-03 12:54:57

  上一篇:go 騰訊應用開發3006 : name lookup timed out 錯誤
  下一篇:go Linux下nginx生成日誌自動切割