DIV CSS 佈局教程網

jQuery 滾動頁面到指定位置彈出浮動層
編輯:JQuery常見問題     

點擊這裡體驗效果,請滾動頁面。

這個效果會在頁面滾動到一定位置時,自動從左側滑出一個可隱藏、可重現的靠邊懸浮層,滑鼠移出內容區時又會自動收起。以下是 HTML 檔案程式碼,存檔後開啟即可:

<!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>
 <title>jquery 滾動頁面到指定位置彈出 div-</title>
 <script type="text/javascript" src="https:///keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script>
 <style type="text/css">
 body{ margin:0px;}
 .onkeleyicom{left:0px;}
 .offkeleyicom{left:-140px;}
 .showkeleyicom{visibility:visible;}
 .hidekeleyicom{visibility:hidden;}
 #xf_keleyi_com{width:166px;height:300px; background-color:transparent;position:fixed;top:300px;}
 #jt_keleyi_com{float:right;width:25px;height:25px;margin-top:80px;}
 #nr_keleyi_com{float:left;height:100%;width:136px;background-color:Silver;}
 </style>
</head>
<body>
 <div style="background-color: #959822; width: 100%; height: 150px;">可以滾動滑鼠使頁面向下</div>
 <div style="background-color: Green; width: 100%; height: 150px;"></div>
 <div style="background-color: Red; width: 100%; height: 150px;">請把光標移到箭頭上</div>
 <div class="offkeleyicom" id="xf_keleyi_com">
 <div id="nr_keleyi_com">這裡是內容</div>
 <div id="jt_keleyi_com"><img src="https:///keleyi/pmedia/rightarrow.jpg" alt="顯示" /></div>
 </div>
 <script type="text/javascript">
 $(document).ready(function () {
 $('#jt_keleyi_com').bind('click', function () { showdiv(); })
 $('#nr_keleyi_com').bind('mouseleave', function () { hidediv(); })
 var m_st, m_po = 600; //滾動到 600 像素時顯示
 $(window).scroll(function () {
 m_st = Math.max(document.body.scrollTop || document.documentElement.scrollTop);
 if (m_st > m_po) { showdiv(); }
 else hidediv();
 })
 })
 function showdiv() {
 $('#xf_keleyi_com').removeClass("offkeleyicom");
 $('#xf_keleyi_com').addClass("onkeleyicom");
 $('#jt_keleyi_com').addClass("hidekeleyicom");
 $('#jt_keleyi_com').removeClass("showkeleyicom");
 }
 function hidediv() {
 $('#xf_keleyi_com').removeClass("onkeleyicom");
 $('#xf_keleyi_com').addClass("offkeleyicom");
 $('#jt_keleyi_com').removeClass("hidekeleyicom");
 $('#jt_keleyi_com').addClass("showkeleyicom");
 }
 </script>
</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved