欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實(shí)現(xiàn)網(wǎng)頁(yè)上隨滾動(dòng)條滾動(dòng)的層效果代碼

 更新時(shí)間:2015年11月04日 09:59:19   作者:企鵝  
這篇文章主要介紹了JS實(shí)現(xiàn)網(wǎng)頁(yè)上隨滾動(dòng)條滾動(dòng)的層效果代碼,涉及JavaScript頁(yè)面元素屬性的獲取、運(yùn)算及設(shè)置等操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了JS實(shí)現(xiàn)網(wǎng)頁(yè)上隨滾動(dòng)條滾動(dòng)的層效果代碼。分享給大家供大家參考,具體如下:

這款網(wǎng)頁(yè)上隨滾動(dòng)條滾動(dòng)層代碼,拖動(dòng)滾動(dòng)條即可看到效果,對(duì)聯(lián)廣告的代碼也都是基于此的,右側(cè)的浮動(dòng)層同樣是可以關(guān)閉的稍微加工,便可實(shí)現(xiàn)一個(gè)浮動(dòng)廣告的代碼,運(yùn)行一下,先看效果吧。

運(yùn)行效果截圖如下:

在線演示地址如下:

http://demo.jb51.net/js/2015/js-web-fixed-scroll-adv-codes/

具體代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>隨滾動(dòng)條滾動(dòng)的層</title>
<style>
body{ margin:0; padding:0; font-size:12px; font-family:"宋體",Arial, Helvetica, sans-serif;}
div,p,ul,ol,li,dl,dt,dd,h1,h2,h3,h4,h5,h6,form,input,form{ margin:0; padding:0;}
h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}
img{ border:0;}
ol,ul{list-style:none;}
a{ text-decoration:none; color:#fff;}
a:hover{ text-decoration:none;}
#scroll_div{ width:100px; height:400px; background:#990; }
#btn_close,#btn_gotop{ cursor:pointer;}
</style>
</head>
<body>
<div style=" width:1002px;height:42px;margin:0 auto; background-color:#060;">頭</div>
<div style="width:1002px; margin:0 auto; background-color:#f60;">
我們提供各類編程源碼、<br>素材、書籍教程、設(shè)計(jì)模板、<br>網(wǎng)頁(yè)特效代碼以及常用軟件下載等,<br>做有質(zhì)量的<br>學(xué)習(xí)型源碼下載站。
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<div style=" width:1002px;height:95px;margin:0 auto; background-color:#060;">底</div>
<div id="scroll_div">
<span id="btn_close">關(guān)閉</span><br />
<span id="btn_gotop">返回頂部</span>
</div>
<script type="text/javascript">
var Bianyuan = {
 //添加事件2(DOM-保證this指向?qū)ο笫莖bj)
 addEvent : function(obj, type, fn){
  if (obj.attachEvent){
   obj['e'+type+fn] = fn;
   obj[type+fn] = function(){obj['e'+type+fn](window.event);}
   obj.attachEvent('on'+type, obj[type+fn]);
  }else{
   obj.addEventListener(type, fn, false);
  }
 },
 //獲取id元素
 $ : function(id){
  return document.getElementById(id);
 },
 //取得瀏覽器可視區(qū)size
 getBrowserSize : function(){
  var pageWidth = window.innerWidth,
   pageHeight = window.innerHeight;
  if (typeof pageWidth != "number"){
   if (document.compatMode == "CSS1Compat"){
    pageWidth = document.documentElement.clientWidth;
    pageHeight = document.documentElement.clientHeight;
   } else{
    pageWidth = document.body.clientWidth;
    pageWidth = document.body.clientHeight;
   }
  }
  //ie減去17滾動(dòng)條寬度
  if(!window.ActiveXObject){
   pageWidth -= 17;
  }
  return {
   width : pageWidth,
   height : pageHeight
  }
 },
 //獲取滾動(dòng)條高度
 getPageScroll : function(){ 
  var yScroll; 
  if (self.pageYOffset) { 
   yScroll = self.pageYOffset; 
  } else if (document.documentElement && document.documentElement.scrollTop){ 
   yScroll = document.documentElement.scrollTop; 
  } else if (document.body) { 
   yScroll = document.body.scrollTop; 
  } 
  return yScroll; 
 }
}
function scrollBar(scrollId, dir, headHeight, footHeight, areaWidth, o){
 //滾動(dòng)框?qū)捀?
 var scrollBar = Bianyuan.$(scrollId),
  barWidth = scrollBar.offsetWidth,
  barHeight = scrollBar.offsetHeight;
 //可視區(qū)寬高
 var pageWidth = Bianyuan.getBrowserSize().width,
  pageHeight = Bianyuan.getBrowserSize().height;
 //內(nèi)容寬高
 var widthMore = document.documentElement.scrollWidth,
  heightMore = document.body.scrollHeight||(document.documentElement.scrollHeight);  
 //最大寬高
 var maxWidth = Math.max(pageWidth, widthMore),
  maxHeight = Math.max(pageHeight, heightMore);
 scrollBar.style.position = 'absolute';
 //設(shè)置top--假設(shè)滾動(dòng)框高度小于整個(gè)頁(yè)面高度,如果大于直接將其隱藏
 if (maxHeight < (barHeight + footHeight + footHeight + 4)){
  scrollBar.style.display = 'none';
 }else{
  //不擋頂部---如果想改距頂高度,改下邊的第一個(gè)2值
  scrollBar.style.top = Bianyuan.getPageScroll() + headHeight + 2 + 'px';
  //不擋底部
  if ((heightMore - Bianyuan.getPageScroll() - barHeight) <= footHeight){
   scrollBar.style.top = heightMore - footHeight - barHeight - 2 + 'px';
  }
 }
 //無(wú)視主體內(nèi)容-左右
 if (dir == 'left' && areaWidth == 1){
  scrollBar.style.left = 2 + 'px';
 }else if (dir == 'right' && areaWidth == 1){
  scrollBar.style.left = maxWidth - barWidth - 2 + 'px';
 //根據(jù)主體內(nèi)容寬-左右
 }else if (dir == 'left' && areaWidth != 1){
  if (pageWidth >= (barWidth*2 + areaWidth + 4)){
   scrollBar.style.left = (pageWidth - areaWidth)/2 - barWidth - 2 + 'px';
  }else{
   scrollBar.style.left = 2 + 'px';
  }
 }else if (dir == 'right' && areaWidth != 1){
  if (pageWidth >= (barWidth*2 + areaWidth + 4)){
   scrollBar.style.left = (pageWidth - areaWidth)/2 + areaWidth + 2 + 'px';
  }else{
   scrollBar.style.left = maxWidth - barWidth - 2 + 'px';
  }
 }
 //關(guān)閉和返回頂部
 if (o){
  if (o.btnClose){
   var closeBtn = Bianyuan.$(o.btnClose);
   Bianyuan.addEvent(closeBtn, 'click', function(){
    scrollBar.style.display = 'none';
   })
  }
  if (o.goTop){
   var gotopBtn = Bianyuan.$(o.goTop);
   Bianyuan.addEvent(gotopBtn, 'click', function(){
    document.documentElement.scrollTop = 0;
    document.body.scrollTop = 0;
   })
  }
 }
 //改變窗口大小或滾動(dòng)條滾動(dòng)
 resizeWindow(scrollId, dir, headHeight, footHeight, areaWidth, o);
}
function resizeWindow(scrollId, dir, headHeight, footHeight, areaWidth, o){
 window.onresize = function(){scrollBar(scrollId, dir, headHeight, footHeight, areaWidth, o);}
 window.onscroll = function(){scrollBar(scrollId, dir, headHeight, footHeight, areaWidth, o);}
}
</script>
<script type="text/javascript">
scrollBar("scroll_div", "right", 42, 95, 1002, {btnClose:"btn_close",goTop:"btn_gotop"});
</script>
</body>
</html>

希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Bootstrap每天必學(xué)之模態(tài)框(Modal)插件

    Bootstrap每天必學(xué)之模態(tài)框(Modal)插件

    Bootstrap每天必學(xué)之模態(tài)框(Modal)插件,模態(tài)框(Modal)是覆蓋在父窗體上的子窗體。通常,目的是顯示來(lái)自一個(gè)單獨(dú)的源的內(nèi)容,可以在不離開(kāi)父窗體的情況下有一些互動(dòng)。子窗體可提供信息、交互等,感興趣的小伙伴們可以參考一下
    2016-04-04
  • 小程序自定義日歷效果

    小程序自定義日歷效果

    這篇文章主要為大家詳細(xì)介紹了小程序自定義日歷效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • javascript中window.open在原來(lái)的窗口中打開(kāi)新的窗口(不同名)

    javascript中window.open在原來(lái)的窗口中打開(kāi)新的窗口(不同名)

    本文給大家介紹使用window.open在原來(lái)的窗口中打開(kāi)新的窗口,涉及到win.open新窗口相關(guān)知識(shí),對(duì)本文感興趣的朋友參考下
    2015-11-11
  • 只有 20 行的 JavaScript 模板引擎實(shí)例詳解

    只有 20 行的 JavaScript 模板引擎實(shí)例詳解

    這篇文章主要介紹了只有 20 行的 JavaScript 模板引擎,結(jié)合實(shí)例形式分析了JavaScript 模板引擎實(shí)現(xiàn)方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2020-05-05
  • js執(zhí)行shell命令的幾種方式(Node)

    js執(zhí)行shell命令的幾種方式(Node)

    在做一個(gè)客戶端基建項(xiàng)目的時(shí)候,多處需要用到JS調(diào)取命令行執(zhí)行shell腳本,本文主要介紹了js執(zhí)行shell命令的幾種方式,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • JavaScript格式化數(shù)字的函數(shù)代碼

    JavaScript格式化數(shù)字的函數(shù)代碼

    當(dāng)要格式化的數(shù)字為null、空或非數(shù)字時(shí),返回的結(jié)果。默認(rèn)為0
    2010-11-11
  • JS數(shù)組操作(數(shù)組增加、刪除、翻轉(zhuǎn)、轉(zhuǎn)字符串、取索引、截取(切片)slice、剪接splice、數(shù)組合并)

    JS數(shù)組操作(數(shù)組增加、刪除、翻轉(zhuǎn)、轉(zhuǎn)字符串、取索引、截取(切片)slice、剪接splice、數(shù)組合并)

    這篇文章主要介紹了JS數(shù)組操作(數(shù)組增加、刪除、翻轉(zhuǎn)、轉(zhuǎn)字符串、取索引、截取(切片)slice、剪接splice、數(shù)組合并)的相關(guān)資料,需要的朋友可以參考下
    2016-05-05
  • 解決layui的form里的元素進(jìn)行動(dòng)態(tài)生成,驗(yàn)證失效的問(wèn)題

    解決layui的form里的元素進(jìn)行動(dòng)態(tài)生成,驗(yàn)證失效的問(wèn)題

    今天小編就為大家分享一篇解決layui的form里的元素進(jìn)行動(dòng)態(tài)生成,驗(yàn)證失效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-09-09
  • 最新評(píng)論