on mouseleave revert image back to origin source that is outside where hover data source is

后端 未结 1 1502
滥情空心
滥情空心 2021-01-28 12:25
function createHover (that) {

  var original = document.getElementsByClassName(\"image_left\"); // attempt

  that.addEventListener(\'mouseover\', function() {
    var          


        
相关标签:
1条回答
  • 2021-01-28 12:51

    var original = document.getElementsByClassName("image_left"); gives you an array of elements with the given class name. So you should first pull one element (or you should use id instead), and assign the source of that image.

    that.addEventListener('mouseleave', function() {
       var origImage = original.length && original[0].src; // assuming the element exists and is an image
        // or original[0].getAttribute("src") depending on whether you want the full source of image or exactly as defined in "src" attribute
       // imageContainer.src = origImage;
    });
    
    0 讨论(0)
提交回复
热议问题