Reputation: 1
I'm about a week and a half into learning jquery but at about 10 hours a day I think I am getting a handle on some things, with help from other posts on here. I am very close to what I want to do. I want to swap the class g1 for p1, but I have to do this for 16 classes. I am considering doing something like this function to remove the number automatically for whichever p number is clicked.
$(function imageswap() {
$("[class^=g]").click(function () {
var num = this.class.slice(1);
var elem = ('.' + 'p' + num);
});
});
Then I would call use $('+elem+) to make use of this. Am I offtrack here or over complicating this?
In addition, how would I make use of this? I initially thought I would use it just as a standard click listener but it doesn't seem to be working. Something like this. Apologies if its a bit amateurish.
$(document).ready ( function(){
$("[class^=g]").click(function () {
var num = this.class.slice(1);
var elem = ('.' + 'p' + num);
$('.portalimg').transition({
display:"none",
});
$(elem).transition({
display:"block",
opacity:"0",
transform: "translateY(-400px) scale(.1,.1)",
'-webkit-transform': "translateY(-400px) scale(.1,.1)",
'-o-transform': "translateY(-400px) scale(.1,.1)",
'-moz-transform': "translateY(-400px) scale(.1,.1)",
},1000);
$(elem).transition({
'-webkit-transform': "translateY(0) scale(1,1)",
'-moz-transform': "translateY(0) scale(1,1)",
'-o-transform': "translateY(0) scale(1,1)",
transform: "translateY(0) scale(1,1)",
"border-radius": "0",
opacity: "1"},2000);
});
});
Upvotes: 0
Views: 31
Reputation: 85575
You don't need to use like $('+elem+)
, you can just use elem
or $(elem)
.
Upvotes: 1