Pra*_*man 10
是的,您可以通过两种方式进行黄色褪色技巧:
:target伪类:<section id="voters">
Content
</section>
Run Code Online (Sandbox Code Playgroud)
各自的CSS
:target {
background: yellow;
}
Run Code Online (Sandbox Code Playgroud)
在点击功能中,如果有,您可以这样做:
$('a[href*="#"]').click(function(){
$($(this).attr("href")).effect("highlight", {}, 1500);
});
Run Code Online (Sandbox Code Playgroud)
或使用animate():
$('a[href*="#"]').click(function(){
$($(this).attr("href")).animate({"background-color": "#ffc"}).delay(2000).animate({"background-color": "transparent"});
});
Run Code Online (Sandbox Code Playgroud)
PS:对于使用 effect(),你需要有这两个JS: effects.core.js 和 effects.highlight.js.
如果您不关心支持所有浏览器,请使用此方法.这是纯CSS,所以这是一个优势.这是一个大纲(包括多个浏览器的多个版本的规则):
.youranchorsclass:active ~ #yourdivsid { /*when the anchor is active (clicked)*/
-moz-animation: myanimation 1s;
-webkit-animation: myanimation 1s;
-o-animation: myanimation 1s;
animation: myanimation 1s;
}
@-moz-keyframes myanimation, @-webkit-keyframes myanimation, @-o-keyframes myanimation, @keyframes myanimation {
from { background: red; }
to { background: white; /*or whatever it was originally*/ }
}
Run Code Online (Sandbox Code Playgroud)
(如果你想摆脱所有那些丑陋的前缀规则,请看看PrefixFree).
如果您关心旧浏览器支持,请使用此选项.在您的页面中包含jQuery,首先将其插入到您的head:
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type = "text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
然后:
$(".yourlink").click(function() {
$("#yourdivid").css("background", "red").delay(1000).css("background", "white");
};
Run Code Online (Sandbox Code Playgroud)
请注意,这个jQuery方法不会逐渐改变颜色,你必须包含一个插件(如jQuery UI)才能这样做.
如果您不想仅为这么小的效果包含一个相对较大的库,请使用此选项.它非常简单,这是一个让你入门的评论大纲:
function changeDivColor(color) {
document.getElementById("yourdivid").style.backgroundColor = color;
}
document.getElementById("youranchor").onClick = function() { //when the anchor is clicked
changeDivColor("red"); //chang the div color to red
setTimeout(function() { //wait 1000 milliseconds (1s) -- see below
changeDivColor("white"); //then change it back to white
}, 1000);
};
Run Code Online (Sandbox Code Playgroud)
希望以任何方式帮助!
| 归档时间: |
|
| 查看次数: |
8410 次 |
| 最近记录: |