The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
+2
alla13
SarkZKalie
6 posters

    Load an image when mouseover on its link

    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1442
    Reputation : 220
    Language : English

    Solved Load an image when mouseover on its link

    Post by SarkZKalie May 24th 2018, 9:17 am

    Hello guys

    I can't explain clearly what I mean but please visit this site.
    Okay, you're in now mouseover on a link https://i.imgur.com/6OiOTQK.gif - you see it? Very Happy

    I'm asking for help to make a script that can let user to view an image from a link without using BBCode or HTML.
    Code:
    Filter :
    Any file type should work : *.jpg, *.png, *.gif (can add more if possible)
    Any image hosting should work : *imgur.com, *servimg.com, *tinypic.com, *postimages.org (only direct link supported)
    Images won't load till user mouseover on its link, except image links already inside a BBCode or HTML tag.

    Code:
    Accepted : http://i.imgur.com/6OiOTQK.gif

    Script won't work if meet conditions below
    Code:
    Unaccepted :
    [img]http://i.imgur.com/6OiOTQK.gif[/img] or
    <img src="http://i.imgur.com/6OiOTQK.gif" />

    Thank you for reading.


    Last edited by SarkZKalie on May 26th 2018, 7:28 am; edited 1 time in total
    alla13
    alla13
    Forumember


    Posts : 91
    Reputation : 6
    Language : Arab5/5 Eng3/5 Fr2/5

    Solved Re: Load an image when mouseover on its link

    Post by alla13 May 24th 2018, 12:30 pm

    i think you want a tooltip on img link but
    instead of a text you want the image to be loaded
    like this gif
    Load an image when mouseover on its link KvEQut7
    if so i am so interested in this
    i hope someone code it for you
    ahmdsat
    ahmdsat
    New Member


    Posts : 23
    Reputation : 2
    Language : عربي

    Solved Re: Load an image when mouseover on its link

    Post by ahmdsat May 24th 2018, 1:24 pm

    i am so interested in this
    Wecoc
    Wecoc
    Forumember


    Male Posts : 144
    Reputation : 111
    Language : Catalan, Spanish, English

    Solved Re: Load an image when mouseover on its link

    Post by Wecoc May 24th 2018, 8:55 pm

    Check this javascript.

    Code:
    /* Image Tooltip v1.0.1 (PunBB) */
     
    $(function() {
     Â $('.post-entry a').filter(function(){
     Â   this.addEventListener("mouseover", function(){ createImageTooltip(this) });
     Â   this.addEventListener("mouseout", function(){ removeImageTooltip() });
     Â });
     Â $('head').append('<style type="text/css">' +
     Â     '.postimage-tooltip {' +
     Â       'border: solid 2px #536482;' +
     Â       'z-index: 999;' +
     Â     '}' +
     Â     '.postimage-tooltip img {' +
     Â       'border: solid 1px #ffffff;' +
     Â     '}' +
     Â '</style>');
    });
     
    function createImageTooltip(data){
     Â if (/.(bmp|webp|png|jpg|gif)$/.test(data.href) && (!/<img/.test(data.innerHTML))){
     Â   var max_width = 192; // Set here the tooltip max width
     Â   var tooltip = $('<div class="postimage-tooltip"><img src="' + data.href +
     Â                   '" style="max-width:' + max_width + 'px" /></div>')[0];
     Â   var offset = $(data).offset();
     Â   $(tooltip).css({
     Â     position: 'absolute',
     Â     display: 'inline-block'
     Â   });
     Â   data.before(tooltip);
     Â   $('.postimage-tooltip').filter(function(){
     Â     $(this).css ({ transform: 'translateY(-' + (this.offsetHeight +  + 'px)' });
     Â   });
     Â }
    }
     
    function removeImageTooltip(){
     Â $('.postimage-tooltip').filter(function(){
     Â   this.remove();
     Â });
    }

    Title: Image Tooltip
    Placement: In all the pages


    Last edited by SarkZKalie on February 6th 2019, 6:55 pm; edited 2 times in total (Reason for editing : Added BMP and WEBP as supported image file formats)
    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1442
    Reputation : 220
    Language : English

    Solved Re: Load an image when mouseover on its link

    Post by SarkZKalie May 25th 2018, 8:14 am

    Thank you so much, Wecoc! But there was a problem appear when I was trying hover on an image link, seem it related to position:absolute and top value.

    Here is the link

    Load an image when mouseover on its link Captur20
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51499
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Load an image when mouseover on its link

    Post by SLGray May 25th 2018, 8:16 am

    Please post a link to a post that contains this and that guests can see.



    Load an image when mouseover on its link Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    Wecoc
    Wecoc
    Forumember


    Male Posts : 144
    Reputation : 111
    Language : Catalan, Spanish, English

    Solved Re: Load an image when mouseover on its link

    Post by Wecoc May 25th 2018, 3:44 pm

    Try this instead. I tested in your forum console and it seems to be working.

    Code:
    /* Image Tooltip v1.0 (Edit) */

    $(function() {
      $('.vglnk').filter(function(){
        this.addEventListener("mouseover", function(){ createImageTooltip(this) });
        this.addEventListener("mouseout", function(){ removeImageTooltip() });
      });
      $('head').append('<style type="text/css">' +
          '.postimage-tooltip {' +
            'border: solid 2px #536482;' +
            'z-index: 999;' +
          '}' +
          '.postimage-tooltip img {' +
            'border: solid 1px #ffffff;' +
          '}' +
      '</style>');
    });
     
    function createImageTooltip(data){
      if (/.(png|jpg|gif)$/.test(data.href) && (!/<img/.test(data.innerHTML))){
        var max_width = 192; // Set here the tooltip max width
        var tooltip = $('<div class="postimage-tooltip"><img src="' + data.href +
                        '" style="max-width:' + max_width + 'px" /></div>')[0];
        var offset = $(data).offset();
        $(tooltip).css({
          position: 'absolute',
          display: 'inline-block'
        });
        data.before(tooltip);
        $('.postimage-tooltip').filter(function(){
          $(this).css ({ transform: 'translateY(-' + (this.offsetHeight + 8) + 'px)' });
        });
      }
    }
     
    function removeImageTooltip(){
      $('.postimage-tooltip').filter(function(){
        this.remove();
      });
    }

    I only changed
    Code:
    $('.post-entry a')
    to
    Code:
    $('.vglnk')

    To use this code in other versions (phpBB2, etc) probably the only thing you have to change is that same thing.
    Also you can change the max width of the tooltip in this line
    Code:
    var max_width = 192;

    The height is changed automatically to preserve the ratio.
    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1442
    Reputation : 220
    Language : English

    Solved Re: Load an image when mouseover on its link

    Post by SarkZKalie May 26th 2018, 7:28 am

    You've made my day!
    Load an image when mouseover on its link Brownb10
    Thank you @Wecoc



    Load an image when mouseover on its link Sarkzk10
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19325
    Reputation : 2005
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: Load an image when mouseover on its link

    Post by Ape May 26th 2018, 5:22 pm

    Problem solved & topic archived.
    Please read our forum rules: ESF General Rules



    Load an image when mouseover on its link Left1212Load an image when mouseover on its link Center11Load an image when mouseover on its link Right112
    Load an image when mouseover on its link Ape_b110
    Load an image when mouseover on its link Ape1010

      Current date/time is September 23rd 2024, 2:28 pm