skip to Main Content

When I hover on the first image it changes and the second div image is also changed and this process in reverse when I hover the first div image is changed and change itself using jQuery?

CLICK ON THIS LINK
https://www.studioairport.nl/ AND GO TO THE Meet our team CONTENT

.our-team{
    border: 1px solid #d3d3d3;
    position: relative;
    overflow: hidden;
}
.our-team img{
    width: 100%;
    height: auto;
}
.our-team .team-content{
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    padding: 45px 18px;
    background: rgba(0,0,0,0.7);
    transform: translateX(-100%);
    transition: all 0.20s ease 0s;
}
/*.our-team:hover .team-content{
    transform: translateX(0);
}*/
.our-team .team-content .post-title{
    font-size: 18px;
    color: #fff;
    text-transform: uppercase;
}
.our-team .team-content .post{
    font-size: 14px;
    color: #cb95e1;
    display: block;
    margin-bottom: 20px;
}
.our-team .description{
    font-size: 14px;
    line-height: 25px;
    color: #fff;
    margin-bottom: 20px;
}
.our-team .team_social{
    margin:0;
    padding:0;
    list-style: none;
}
.our-team .team_social li{
    display: inline-block;
    margin-right: 5px;
}
.our-team .team_social li a{
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #f5f5f5;
    font-size: 17px;
    color: #f5f5f5;
    line-height: 40px;
    text-align: center;
    display: inline-block;
    transition: border 0.3s ease 0s;
}
.our-team .team_social li a:hover{
    border-color: transparent;
}
.our-team .team-prof{
    width: 100%;
    position: absolute;
    bottom: 0;
    text-align: right;
    padding: 20px 16px;
    background: rgba(0,0,0,0.7);
    transform: translateX(0);
    transition: all 0.20s ease 0s;
}
/*.our-team:hover .team-prof{
    transform: translateX(100%);
}*/
.our-team .team-prof .post-title{
    font-size: 18px;
    color: #fff;
    margin: 0 0 8px 0;
    text-transform: uppercase;
}
.our-team .team-prof .post{
    font-size: 14px;
    color: #cb95e1;
    margin-bottom: 0;
}
@media only screen and (max-width: 990px) {
    .our-team{ margin-bottom: 20px; }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 

 <div class="container">
    <div class="row">
        <div class="col-md-3 col-sm-6 col-xs-6">
            <div class="our-team">
                <img class="xyz"  src="http://jqueryrain.com/tutorial/our-team/demo30/images/img-2.jpg" alt="">
                <div class="team-content">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post">Web Desginer</span>
                    <p class="description">
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio exercitationem facilis laborum perferendis quasi, ratione.
                    </p>
                    <ul class="team_social">
                        <li><a href="#"><i class="fa fa-linkedin"></i></a></li>
                        <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                        <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
                        <li><a href="#"><i class="fa fa-pinterest"></i></a></li>
                    </ul>
                </div>
                <div class="team-prof">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post">Web Desginer</span>
                </div>
            </div>
        </div>
		<div class="col-md-3 col-sm-6 col-xs-6">
            <div class="our-team">
                <img src="http://jqueryrain.com/tutorial/our-team/demo30/images/img-1.jpg" alt="">
                <div class="team-content">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post">Web Desginer</span>
                    <p class="description">
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio exercitationem facilis laborum perferendis quasi, ratione.
                    </p>
                    <ul class="team_social">
                        <li><a href="#"><i class="fa fa-linkedin"></i></a></li>
                        <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                        <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
                        <li><a href="#"><i class="fa fa-pinterest"></i></a></li>
                    </ul>
                </div>
                <div class="team-prof">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post">Web Desginer</span>
                </div>
            </div>
        </div>
		<div class="col-xs-6 col-md-3 col-sm-6">
            <div class="our-team">
                <img src="http://jqueryrain.com/tutorial/our-team/demo30/images/img-1.jpg" alt="">
                <div class="team-content">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post ">Web Desginer</span>
                    <p class="description">
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio exercitationem facilis laborum perferendis quasi, ratione.
                    </p>
                    <ul class="team_social">
                        <li><a href="#"><i class="fa fa-linkedin"></i></a></li>
                        <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                        <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
                        <li><a href="#"><i class="fa fa-pinterest"></i></a></li>
                    </ul>
                </div>
                <div class="team-prof">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post">Web Desginer</span>
                </div>
            </div>
        </div>
		<div class="col-md-3 col-sm-6 col-xs-6">
            <div class="our-team">
                <img src="http://jqueryrain.com/tutorial/our-team/demo30/images/img-1.jpg" alt="">
                <div class="team-content">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post">Web Desginer</span>
                    <p class="description">
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio exercitationem facilis laborum perferendis quasi, ratione.
                    </p>
                    <ul class="team_social">
                        <li><a href="#"><i class="fa fa-linkedin"></i></a></li>
                        <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                        <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
                        <li><a href="#"><i class="fa fa-pinterest"></i></a></li>
                    </ul>
                </div>
                <div class="team-prof">
                    <h3 class="post-title">Williamson</h3>
                    <span class="post">Web Desginer</span>
                </div>
            </div>
        </div>
    </div>
</div>

6

Answers


  1. you can use it with simple inline javascript

    <img src="http://jqueryrain.com/tutorial/our-team/demo30/images/img-1.jpg" alt="" onmouseover="this.src='http://jqueryrain.com/tutorial/our-team/demo30/images/img-2.jpg'"  onmouseout="this.src='http://jqueryrain.com/tutorial/our-team/demo30/images/img-1.jpg'">
    

    or using jquery

    <img src="http://jqueryrain.com/tutorial/our-team/demo30/images/img-1.jpg" alt="" data-hover-src="this.src='http://jqueryrain.com/tutorial/our-team/demo30/images/img-2.jpg'"  data-normal-src="this.src='http://jqueryrain.com/tutorial/our-team/demo30/images/img-1.jpg'">
    
    $("img")
      .on( "mouseenter", function() {
         $(this).attr("src", $(this).data('hover-src'));
     })
     .on( "mouseleave", function() {
         $(this).attr("src", $(this).data('normal-src'));
    });
    
    Login or Signup to reply.
  2. You can declare an attribute in each of your <img /> tags, something like data-replacement:

    <img class="xyz" data-replacement="/image/my_replacement_image.jpg" src="..." alt="" />
    

    Then you can use jQuery hover method:

    $(".our-team img").hover(function() {
        var img = $(this);
        // store current src in image data
        img.data('src', img.attr("src"));
        // replace
        img.attr("src", img.data('replacement'));
    },
    function(){
        // restore src
        $(this).attr('src', img.data('src'));
    });
    
    Login or Signup to reply.
  3. set background image using css instead of html
    Try This

    HTML :

    <div class="our-team">
       <div class="img-block"></div>
    

    CSS:

    .img-block{ 
     background: url("img-1.jpg") no repeat;
     background-position:2px 2px;
     }
    

    Change image on hover:

    .img-block:hover{ 
          background:url("img-2.jpg") no repeat;
     }
    

    You can set background position and required image path acoording to your need

    Login or Signup to reply.
  4. Try this also

    Take an id in img tag

    #idname:hover{ background:url("img2.png"); }
    
    Login or Signup to reply.
  5. Instead of using img tag, If you use those image in background. It is easy to handle it in css itself.

    This is an HTML mockup:

    <div style="background-image: url(image-1.jpg)"></div>
    

    Here is CSS:

    div:hover {
    background-image: url(image-2.jpg);
    }
    
    Login or Signup to reply.
  6. Hint to ‘JavaScript/jQuery Less’ Solution. Recommend you not to use jQuery/Javascript for this simple task.

        <div class='image-container'>
        <img class="xyz" src="http://pnge.org/wp-content/uploads/2016/12/images.jpg" alt="" height='100' width='200' />
        <img class="xyz-replacement" src="http://chainimage.com/images/3d-wallpapers-amazing-wallpapers-tigers-wallpapers-white-tiger.jpg" alt="" height='100' width='200' />
        </div>
    
    <style>
          .image-container{
        	position: relative;
        }
        .image-container:hover .xyz-replacement {
        	display: block;
        }
        .xyz-replacement{
        	display: none;
        	position: absolute;
          bottom: 0;
        	z-index: 9;
        }
      
      </style>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search