jQuery相關紀錄
October 7, 2015
August 19, 2012
於head間置放:
<script type="text/javascript" src="{js}/jquery.js"></script>
<script type="text/javascript" src="{js}/ui.core.js"></script>
<script type="text/javascript" src="{js}/jquery.scroll-follow.js"></script>
<script type="text/javascript">
$( document ).ready( function (){
$('#sideBar').scrollFollow({});
});
//option
$( document ).ready( function () {
$( '#sideBar' ).scrollFollow( {
speed: 2000,
offset: 0,
killSwitch: 'exampleLink',
onText: 'Disable Follow',
offText: 'Enable Follow'
} );
} );
</script>
<script type="text/javascript" src="{js}/ui.core.js"></script>
<script type="text/javascript" src="{js}/jquery.scroll-follow.js"></script>
<script type="text/javascript">
$( document ).ready( function (){
$('#sideBar').scrollFollow({});
});
//option
$( document ).ready( function () {
$( '#sideBar' ).scrollFollow( {
speed: 2000,
offset: 0,
killSwitch: 'exampleLink',
onText: 'Disable Follow',
offText: 'Enable Follow'
} );
} );
</script>
※speed: 2000,(速度)
※offset: 0,(top位置)
Requirements (必備零件)
jQuery (tested with 1.2.6)
jQuery UI Core (tested with 1.5.2)
Optional (追加零件)
jQuery Easing Plugin
jQuery Cookie Plugin
DEMO:
http://blog.apao.idv.tw/sample/ScrollFollow/index.html
出處:
http://kitchen.net-perspective.com/open-source/scroll-follow/
August 16, 2012
使用CSS需要寫一大串將footer的部份固定在最下方,但jQuery提供了很方便的方式
使用方式如下:
1.下載並放置於伺服器的適當path
2.html head 中要加:
<script type="text/javascript" src="js/footerFixed.js"></script>
3.在html div的 footer部份中再寫入:
<div id=footer></div>
demo:
http://blog.apao.idv.tw/sample/footerFixed/
February 1, 2012
February 1, 2012
<style>
ul {list-style:none;margin:0;padding:0;}
li {float:left;width:100px;line-height:25px;height:25px;margin:0;padding:0;text-align:center;}
li a {background:url(背景圖片) repeat 0 0;display:block;padding:5px 10px;color:#FFF;text-decoration:none;border-right:1px solid #FFF;}
</style>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jquery.bgpos.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('li a')
.css( {backgroundPosition: "-20px 35px"} ) //デフォルト時、背景画像を横-20px、縦35pxに指定。
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
//マウスオーバー時に縦位置94pxに0.5秒かけて移動
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
//マウスアウト時に横位置40px、縦位置35pxに2秒かけて移動
$(this).css({backgroundPosition: "-20px 35px"})
//移動完了後、元の位置に戻す
}})
})
});
</script>
ul {list-style:none;margin:0;padding:0;}
li {float:left;width:100px;line-height:25px;height:25px;margin:0;padding:0;text-align:center;}
li a {background:url(背景圖片) repeat 0 0;display:block;padding:5px 10px;color:#FFF;text-decoration:none;border-right:1px solid #FFF;}
</style>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jquery.bgpos.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('li a')
.css( {backgroundPosition: "-20px 35px"} ) //デフォルト時、背景画像を横-20px、縦35pxに指定。
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
//マウスオーバー時に縦位置94pxに0.5秒かけて移動
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
//マウスアウト時に横位置40px、縦位置35pxに2秒かけて移動
$(this).css({backgroundPosition: "-20px 35px"})
//移動完了後、元の位置に戻す
}})
})
});
</script>
html中放置
<ul id="demo">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
備註:詳細可參考demo中CSS ID+Script的作法,可分好幾種動畫。
$('#a a')
.css( {backgroundPosition: "-20px 35px"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
$(this).css({backgroundPosition: "-20px 35px"})
}})
})
.css( {backgroundPosition: "-20px 35px"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
$(this).css({backgroundPosition: "-20px 35px"})
}})
})
出處:
http://snook.ca/technical/jquery-bg/
參考:
http://www.skuare.net/test/jBgpos.html
demo:
http://apao.zapto.org/~apao/jQuery/Background_Position/
February 1, 2012
下載以下各個.js後,放入[head]~[/head]之間
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js"></script>
<script type="text/javascript" src="jquery.easing.1.3.js"></script>
<script type="text/javascript" src="jquery.hoverIntent.minified.js"></script>
<script type="text/javascript" src="jquery.flashyNav.1.0.js"></script>
<script type="text/javascript">
$(function(){
$('.nav1').flashyNav({
rolloverColor: '#5400ff', //the default color of the rollover element
rolloverDuration: 1000, //the default duration for the rollover
easingMethod: 'easeInOutQuint' //easing method used for animation
});
$('.nav2').flashyNav({
rolloverColor: '#00d2ff', //the default color of the rollover element
rolloverDuration: 800, //the default duration for the rollover
easingMethod: 'easeOutBounce' //easing method used for animation
});
$('.nav3').flashyNav({
rolloverColor: '#a800ff', //the default color of the rollover element
rolloverDuration: 800, //the default duration for the rollover
easingMethod: 'easeOutElastic' //easing method used for animation
});
});
</script>
<style type="text/css">
* {margin:0; padding:0}
body {background: #000; color:#fff; margin:20px; font-family:Arial, Helvetica, sans-serif; font-size:11px}
a {color:#fff}
ul.nav {list-style:none; margin:20px; width:300px; font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:bold}
ul.nav li {position:relative; border-bottom:1px solid #333; display:block; height:30px; overflow:hidden}
ul.nav li a {position:relative; color:#fff; text-decoration:none; display:block; height:20px; padding:10px 0 0 10px; z-index:100; text-transform:uppercase}
</style>
<script type="text/javascript" src="jquery.easing.1.3.js"></script>
<script type="text/javascript" src="jquery.hoverIntent.minified.js"></script>
<script type="text/javascript" src="jquery.flashyNav.1.0.js"></script>
<script type="text/javascript">
$(function(){
$('.nav1').flashyNav({
rolloverColor: '#5400ff', //the default color of the rollover element
rolloverDuration: 1000, //the default duration for the rollover
easingMethod: 'easeInOutQuint' //easing method used for animation
});
$('.nav2').flashyNav({
rolloverColor: '#00d2ff', //the default color of the rollover element
rolloverDuration: 800, //the default duration for the rollover
easingMethod: 'easeOutBounce' //easing method used for animation
});
$('.nav3').flashyNav({
rolloverColor: '#a800ff', //the default color of the rollover element
rolloverDuration: 800, //the default duration for the rollover
easingMethod: 'easeOutElastic' //easing method used for animation
});
});
</script>
<style type="text/css">
* {margin:0; padding:0}
body {background: #000; color:#fff; margin:20px; font-family:Arial, Helvetica, sans-serif; font-size:11px}
a {color:#fff}
ul.nav {list-style:none; margin:20px; width:300px; font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:bold}
ul.nav li {position:relative; border-bottom:1px solid #333; display:block; height:30px; overflow:hidden}
ul.nav li a {position:relative; color:#fff; text-decoration:none; display:block; height:20px; padding:10px 0 0 10px; z-index:100; text-transform:uppercase}
</style>