Reputation: 259
I currently have jQuery functions that use mouseenter and mouseleave. This currently gives me the desired effect where everything is returned to normal once the mouse leaves a div. I am trying to replicate this but instead using click, I was reading up about on() and off() but I do not think this can be used. Below is my code.
jQuery(".leftpara").hide();
jQuery(".rightpara").hide();
jQuery('#home-grid-one-two').mouseenter(function(){
$('#home-grid-two-one').css({
'visibility': 'hidden'
});
$('#home-grid-two-two').css({
'visibility': 'hidden'
});
$('#home-grid-two-three').hide();
$('#home-grid-three-three').hide();
jQuery(".leftpara").show();
jQuery(".rightpara").show();
jQuery(".ptagexp").hide();
});
jQuery('#home-grid-one-two').mouseleave(function(){
$('#home-grid-two-one').css({
'visibility': 'visible'
});
$('#home-grid-two-two').css({
'visibility': 'visible'
});
$('#home-grid-three-two').show();
$('#home-grid-two-one').show();
$('#home-grid-three-one').show();
$('#home-grid-two-three').show();
$('#home-grid-three-three').show();
jQuery(".leftpara").hide();
jQuery(".rightpara").hide();
jQuery(".ptagexp").show();
HTML
<div id="home-grid-one-one" class="home-grid">
<div class="page" title="Page 2">
<p class="leftpara"> Some Text.</p>
</div>
<div id="home-grid-one-two" class="home-grid"> <div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 6">
<div class="layoutArea">
<div class="column">
<p style="text-align: center;">Anthony &
Thomas</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="home-grid-one-three" class="home-grid"> <div class="page" title="Page 2">
<p class="rightpara"> Some Text.</p>
</div>
<div id="home-grid-two-one" class="home-grid"> <div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 6">
<div class="layoutArea">
<div class="column">
<p style="text-align: center;">Award winning</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="home-grid-two-two" class="home-grid"> <div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 6">
<div class="layoutArea">
<div class="column">
<p style="text-align: center;"><strong>Proven
to deliver</strong></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="home-grid-two-three" class="home-grid"> <div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 6">
<div class="layoutArea">
<div class="column">
<p style="text-align: center;">Development
Process</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="home-grid-three-one" class="home-grid"> <div class="page" title="Page 2"></div>
<div class="page" title="Page 2"></div>
<div id="home-grid-three-two" class="home-grid"> <div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 2">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 6">
<div class="layoutArea">
<div class="column">
<p class="ptagexp" style="text-align: center;">Experience in
many markets</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="home-grid-three-three" class="home-grid"> <div class="page" title="Page 2"></div>
Upvotes: 1
Views: 73
Reputation: 259
I managed to get the desired effect by adding a counter in each function. I first off initialize the counter variable and then in the click trigger I add one. I then have an IF statement so when the clicks reach 2 it changes the values back to default and resets the counter. Below is an example
(function() {
var count = 0;
jQuery('#home-grid-one-two').click(function () {
count += 1;
jQuery('#home-grid-two-one').css({
'visibility': 'hidden'
});
jQuery('#home-grid-two-two').css({
'visibility': 'hidden'
});
jQuery('#home-grid-two-three').hide();
jQuery('#home-grid-three-two').css('background-image', 'url("A PICTURE")');
jQuery('#home-grid-three-two').css({
'background-size': 'cover'
});
jQuery('#home-grid-three-three').hide();
jQuery('#home-grid-two-two').css({
'margin-top': '-450px'
});
jQuery('#home-grid-three-two').css({
'margin-top': '-420px'
});
jQuery(".leftpara").show();
jQuery(".rightpara").show();
jQuery(".ptagexp").hide();
if (count == 2) {
jQuery('#home-grid-two-one').css({
'visibility': 'visible'
});
jQuery('#home-grid-two-two').css({
'visibility': 'visible'
});
jQuery('#home-grid-three-two').show();
jQuery('#home-grid-three-two').css('background-image', 'none');
jQuery('#home-grid-two-two').css({
'margin-top': '0px'
});
jQuery('#home-grid-three-two').css({
'margin-top': '0px'
});
jQuery('#home-grid-two-one').show();
jQuery('#home-grid-three-one').show();
jQuery('#home-grid-two-three').show();
jQuery('#home-grid-three-three').show();
jQuery(".leftpara").hide();
jQuery(".rightpara").hide();
jQuery(".ptagexp").show();
count = 0;
}
});
})();
Upvotes: 0
Reputation: 3131
An example of jquery click event are as below
jQuery(".leftpara").click(function(){
//do something here
});
or
jQuery(".leftpara").on("click",function(){
//do something here
});
or
jQuery(document).on("click",".leftpara",function(){
//do something here
});
Upvotes: 1