Last active
December 4, 2016 12:09
-
-
Save guangningyu/478317c49e5bbd02f567b2dfb869187a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 鼠标移入背景色变浓,移出变淡 | |
$(document).ready(function() { // $(document)是一个封装好的函数,将DOM映射为一个jQuery对象 | |
$('div').mouseenter(function() { | |
$('div').fadeTo('fast', 1); // 0.25是透明度,1代表完全不透明 | |
}) ; | |
$('div').mouseleave(function() { | |
$('div').fadeTo('fast', 0.5); | |
}) ; | |
}); | |
// 可以在jQuery内部定义变量 | |
$(document).ready(function() { | |
var $target = $('ol > li:nth-child(4)'); // $target可以写成任意值(如target),这里的$只是按惯例的命名规则 | |
$target.fadeOut('fast'); | |
}); | |
// 可以按class选取元素 | |
$(document).ready(function() { | |
$('button').click(function() { //双击是.dblclick | |
$('.vanish').fadeOut('slow'); | |
}); | |
}); | |
// 也可以根据id选取元素 | |
$(document).ready(function() { | |
$('button').click(function() { | |
$('#blue').fadeOut('slow'); | |
}); | |
}); | |
// 可以同时选取多个元素 | |
$('p, li').fadeTo('slow', 0); //This is called a compound selector. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment