需要帮助,使这个简单的 JQuery 图像悬停脚本仅在禁用 javascript 时才弃用为 CSS
我目前有一个非常基本的 JQuery 脚本,附带一些 CSS,当有人将鼠标悬停在我网站上的产品图像上时,它有助于创建平滑的淡入淡出效果。然而,我希望能够做的是允许禁用 Javascript 的用户仍然仅通过 CSS 获得基本的显示/隐藏悬停效果。如何实现这一点?
谢谢
这是我目前要给你的想法:
HTML
<li>
<a href="<?php the_permalink(); ?>" class="product_view_sm">..View Item..</a>
<?php the_post_thumbnail('prod-img-sm', array('class' => 'single_product_img_sm', 'alt' => 'View Product')); ?>
</li>
CSS
ul.product_list_sm li {
overflow: hidden;
width: 192px;
height: 192px;
margin-right: 15px;
margin-bottom: 15px;
float: left;
position: relative;
}
a.product_view_sm {
font-family: aaaiightRegular;
font-size: 15px;
font-weight: normal;
color: #000000;
background: url(images/epr_store_product_overlay.png) no-repeat;
width: 184px;
height: 59px;
padding: 125px 0px 0px 0px;
position: absolute;
top: 4px;
left: 4px;
display: block;
text-align: center;
z-index: 200;
}
img.single_product_img_sm {
position: absolute;
top: 0px;
left: 0px;
z-index: 100;
}
JQuery
// Fade anchor graphic in on hover for small products
$(document).ready(function() {
$('a.product_view_sm').css("opacity","0");
$('.product_list_sm li').hover(
function(){
$(this).find('a.product_view_sm').animate({
opacity: 1
}, 250);
},
function(){
$(this).find('a.product_view_sm').animate({
opacity: 0
}, 250);
}
);
});
I currently have a very basic JQuery script accompanied by some CSS that helps create a smooth fading effect for when someone hovers over a product image on my site. What Id like to be able to do however is allow users that have Javascript disabled to still get a basic show/hide hover effect via CSS only. How might this be accomplished?
Thanks
Here is what I currently have going to give you an idea:
HTML
<li>
<a href="<?php the_permalink(); ?>" class="product_view_sm">..View Item..</a>
<?php the_post_thumbnail('prod-img-sm', array('class' => 'single_product_img_sm', 'alt' => 'View Product')); ?>
</li>
CSS
ul.product_list_sm li {
overflow: hidden;
width: 192px;
height: 192px;
margin-right: 15px;
margin-bottom: 15px;
float: left;
position: relative;
}
a.product_view_sm {
font-family: aaaiightRegular;
font-size: 15px;
font-weight: normal;
color: #000000;
background: url(images/epr_store_product_overlay.png) no-repeat;
width: 184px;
height: 59px;
padding: 125px 0px 0px 0px;
position: absolute;
top: 4px;
left: 4px;
display: block;
text-align: center;
z-index: 200;
}
img.single_product_img_sm {
position: absolute;
top: 0px;
left: 0px;
z-index: 100;
}
JQuery
// Fade anchor graphic in on hover for small products
$(document).ready(function() {
$('a.product_view_sm').css("opacity","0");
$('.product_list_sm li').hover(
function(){
$(this).find('a.product_view_sm').animate({
opacity: 1
}, 250);
},
function(){
$(this).find('a.product_view_sm').animate({
opacity: 0
}, 250);
}
);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据你的javascript,这应该在没有动画的情况下做同样的事情
Based on your javascript, this should do the same thing without the animation