javascript - JQuery set two imgs to same position as another -


i have been tring set img @ same position using jquery .position() , .css()

here code:

function setimgstosameposition() {     var position = $('#img1').position();     $('#img2').css({ 'left': position.left + 'px', 'top': position.top + 'px' });     $('#img3').css({ 'left': position.left + 'px', 'top': position.top + 'px' }); }  $(document).ready(function () {     // set imgs pos equal img1 pos     setimgstosameposition(); }) 

any thoughts?

you can overlap images way. set position fixed set left , top values both other images. i'm not entirely sure why'd want this; so, if it's not desired result, comment.

function setimgstosameposition() {      var position = $('#img1').position();      $('#img2, #img3').css({ 'left': position.left + 'px', 'top': position.top + 'px' });  }    $(document).ready(function () {      // set imgs pos equal img1 pos      setimgstosameposition();  })
img {    width:100px;    height:100px;    border:1px solid black;  }    #img1, #img2, #img3 {    position:fixed;  }    #img1 {    left:50px;    top:50px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <img id="img1" src="http://neil.computer/stack/bg.jpg" />  <img id="img2" src="http://neil.computer/stack/bg2.jpg" />  <img id="img3" src="http://neil.computer/stack/bg3.jpg" />


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -