first off I know this can be achieved purely with CSS but I have recently learned jQuery and though I would have a crack at doing it via jQuery instead to help in improve my skills.
首先,我知道这可以纯粹用CSS实现,但我最近学习了jQuery,虽然我会通过jQuery做一个破解,而不是帮助提高我的技能。
I am trying to make it so when I mouse over an image it goes to half opacity... I know it should be simple. but I think I must be missing something my markup is <img class="port-item-img" src="...">
and my script is
我试图这样做,当我将鼠标移到图像上时,它会变成一半不透明......我知道它应该很简单。但我想我必须遗漏我的标记并且我的脚本是
$(document).ready(function(){
$(".port-item-img").hover(function() {
$(this).css("opacity", "0.5");
};
);
});
any reason this shouldn't work?
任何原因这不起作用?
4 个解决方案
#1
0
this should work
这应该工作
$(document).ready(function(){
$(".port-item-img").hover(function() {
$(this).css("opacity", "0.5");
});
});
you added ;
for }
你补充说;为}
#2
0
You had an extra semi-colon. Remove that and make sure you include jQuery and an image that has a proper url.
你有一个额外的分号。删除它,并确保包含jQuery和具有正确URL的图像。
$(document).ready(function () {
$(".port-item-img").hover(function () {
$(this).css("opacity", "0.5");
}); //<--- Here was an extra ;
});
#3
0
$(document).ready(function(){
$(".port-item-img").hover(function() {
$(this).css("opacity", "0.5");
}; // extra ;
);
});
#4
0
for those wondering.... is was a wordpress issue, wordpress doesn't allow $(document).ready(){};
syntax instead you need to use jQuery(document).ready($){};
对于那些想知道....是一个wordpress问题,wordpress不允许$(document).ready(){};语法而不是你需要使用jQuery(document).ready($){};
#1
0
this should work
这应该工作
$(document).ready(function(){
$(".port-item-img").hover(function() {
$(this).css("opacity", "0.5");
});
});
you added ;
for }
你补充说;为}
#2
0
You had an extra semi-colon. Remove that and make sure you include jQuery and an image that has a proper url.
你有一个额外的分号。删除它,并确保包含jQuery和具有正确URL的图像。
$(document).ready(function () {
$(".port-item-img").hover(function () {
$(this).css("opacity", "0.5");
}); //<--- Here was an extra ;
});
#3
0
$(document).ready(function(){
$(".port-item-img").hover(function() {
$(this).css("opacity", "0.5");
}; // extra ;
);
});
#4
0
for those wondering.... is was a wordpress issue, wordpress doesn't allow $(document).ready(){};
syntax instead you need to use jQuery(document).ready($){};
对于那些想知道....是一个wordpress问题,wordpress不允许$(document).ready(){};语法而不是你需要使用jQuery(document).ready($){};