0

I am using a web template which have a jquery slider that uses jQuery touchTouch.jquery.js plugin version 1.0 . a live sample of the slider can be accessed from this link web templete . now inside the web template i got the following markup :-

<div class="row">
                <ul class="listgall">
                    <li class="col-lg-4 col-md-4 col-sm-6  col-xs-6 colgal">
                        <figure><a href="img/page3_bigimg1.jpg" class="thumb"><img src="img/page3_img1.jpg" alt=""><span><strong>Project name:<strong><em>Lorem ipsum dolore massa</em><img src="img/searchsmall.png" alt=""></span></a></figure>
                    </li>

this will do 2 things:-

1.it will show the following when i hover over an image :-

<span><strong>Project name:<strong><em>Lorem ipsum dolore massa</em><img src="img/searchsmall.png" alt=""></span>

2.if i click on the page3_img1.jpg image , then the <a href="img/page3_bigimg1.jpg" class="thumb"> image will be shown inside the slider.

Now i have the following questions, on how i can add these features.

  1. when the image is rendered inside the slider , how i can show this markup inside the slider image as a fixed text ? :-

    Project name:Lorem ipsum dolore massa

As currently when the image is rendered inside the slider no text or description will be shown even if i hover over it ?

  1. second question . now i have 2 web pages that uses the slider feature. and inside one web page i want to hide the next and previous arrows inside the slider while to show these arrows inside the second web page,, so is this possible , or in this case i need to have two versions of the touchTouch.query.js files and load them separately inside each web page ?

-----------------------EDIT-----------------------------

now after many tests and modifications i did the following modification to the loadImage callback function inside the Touchtouch script :-

function loadImage(src, callback){
            var img = $('<img>').on('load', function(){
                callback.call(img);
            });

            img.attr('src', src);



                // get all the captions (should probably be done with variable referring to something about above selector)
                var allcaptions = $("figure span");

                // setTimeout is a hack here, since the ".placeholders" don't exist yet
                setTimeout(function () {
                    $(".placeholder").each(function (i) {

                        // in each .placeholder, copy its caption's mark-up into it (remove the img first)
                        var caption = allcaptions.eq(i).clone();
                       // caption.find("img").remove();
                        $(this).append("<div class='caption'>" + caption.html() + "</div>");
                    });
        }, 500
        );
}

this seems to show the span correctly as follow:-

enter image description here

but i am facing this problem when i deploy the website to my hosting server (where there is internet delay, unlike working locally on my machine), now when i click on an image it will show the slider and a loading image with the caption as follow:-

enter image description here

then when the image is fully rendered the caption will be removed , and only the image will be shown without the caption text. now if i click on next & previous arrows inside the slider where the image will be loaded from the browser cache ,, there will not be any loading time and the caption will be shown correctly. so is there a way to fix this , for example to modify my script to show the caption text only when the image is fully rendered ? so can anyone adivce how i can fix this issue ?

John John
  • 1
  • 72
  • 238
  • 501
  • 1
    Try defining `data-*` attribute at `.placeholder` elements having expected text to be displayed, utilizing `css` `:before` pseudo selector at `#gallerySlider.placeholder` to display text at `data-*` `html` – guest271314 Sep 02 '15 at 02:40
  • @guest271314 can you adivce more on your reply any available sample code? – John John Sep 02 '15 at 21:58
  • _"can you adivce more on your reply any available sample code?"_ See post – guest271314 Sep 03 '15 at 01:11
  • @guest271314 can you please check my edit section on the original question, where i modified the built-in loadimage call back function , but i faced some issues – John John Sep 09 '15 at 01:11

2 Answers2

1
  1. Here is a mock-up pulling in touchTouch and some of your files, while also adding some extra JS functionality and CSS to get the caption to show when the image is enlarged in the slider:

    http://jsfiddle.net/dx8qdoph/

    Some notes: I didn't bother with the captions sliding in and out on hover (I just hid them). The setTimeout part of it is a bit of a hack to save me time. I added the setTimeout since the .placeholder elements that touchTouch adds don't yet exist when the thumbnails are clicked. The right way would presumably be to append the captions after a timeout loop or MutationObserver or something like that tells you when they exist (not my forte). Alternatively, if it's an option for you to customize the touchTouch.jquery.js file, you could make the caption-adding JS in there instead.

  2. I don't think you should need two versions of touchTouch to hide the arrows in one implementation and not the other. You can see in the fiddle that I just hid the arrows by display:none'ing them in CSS (you can still use arrow keys to go back and forth).

Max Starkenburg
  • 1,499
  • 1
  • 15
  • 21
  • thanks for the sample , but i have this question:- how i can show the text inside the image itself as shown on the web template link i provided, as in your jsfiddle sample the text will be shown below the image and not inside it.can u adivce please – John John Sep 02 '15 at 22:01
  • 1
    Do you mean something like [this](http://jsfiddle.net/dx8qdoph/1/) (except with the right edge of the caption block aligned with the right edge of the photo (something that doesn't always happen))? Let me know if that's what you mean before I explain further what you'd need to do. – Max Starkenburg Sep 03 '15 at 01:14
  • thanks for your help. but seems i did not explain what i need exactly. now in the following web template image gallary http://static.livedemo00.template-help.com/wt_47767/index-2.html when you hover over an image a text and a search icon will be shown, then if you click on the image it will be shown inside jquery slider. now when the image is displayed inside the slider no text is being shown. so what i need is to show the same text and search icon inside the image when it is being shown inside the jQuery slider.... can you adivce ? – John John Sep 03 '15 at 13:58
  • Ok, I'm still not sure if I'm understanding what you need and what is lacking in the mock-up. Does this one help? http://jsfiddle.net/dx8qdoph/3/ – Max Starkenburg Sep 03 '15 at 16:09
  • something which makes me get confused is that the markup you are using to construct the image gallery is somehow different than the one used inside the web template, where inside the template they construct the image gallery as follow "
    Project name:Lorem ipsum dolore massa
    "
    – John John Sep 03 '15 at 16:42
  • while you uses "
    Project ONE:Lorem ipsum dolore massa ONE
    "
    – John John Sep 03 '15 at 16:42
  • 1
    It's _just_ a proof-of-concept mock-up. It's just supposed to be a simplified example to show you what I was trying to convey, without adding a bunch of distractions, or making it exactly like you would (I only have so much time). You will have to adjust things to fit the exact layout/mark-up/behavior of your implementation. If you don't understand enough JS/CSS/HTML to do that, then I probably can't help you much further. Here is another version using
    ...
    : http://jsfiddle.net/dx8qdoph/4/. For the CSS/JS, I only had to change the selectors. Good luck.
    – Max Starkenburg Sep 03 '15 at 18:36
  • ok i run your code inside my application, but it will only work when i first click on an image,, but if i click on next arrow inside the jquery slider then the image will keep loading and i will only get the text and the search button without the image.. – John John Sep 03 '15 at 23:05
  • i tired your code on my current system but i noted the following problem, Currently if i click on the next and previous arrows inside the jquery slider, the rendered images will be shown on the bottom of the page for around 1 second then it will re-position on the middle,, not sure if this is related to the timer you defined inside the touch scrip ? becuase before adding the custom timer i did not face this problem ... can you adivce if i can fix this ? and thanks for the great code and help so far. – John John Sep 08 '15 at 01:23
  • I doubt the setTimeout is related, because in my example, it's unrelated to the clicking of the prev/next arrows. But who knows. As I noted in my answer, the setTimeout I put was just a temporary hack. Your real implementation should something that doesn't rely on a static time of 2 seconds, but rather checks to see whether the .placeholder divs have been created yet. You may find some of these answers useful: http://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists – Max Starkenburg Sep 08 '15 at 13:26
  • can you please check my edit section on the original question, where i modified the built-in loadimage() call back function as mentioned on your example, but i faced some issues .. seems that your approach is the way to go with, as i tried many other approaches and none of them worked... can you please check my edit and adivce ? many thanks – John John Sep 09 '15 at 01:13
  • i modified the css files and got the effect i want.. thanks a lot for your help.. – John John Sep 10 '15 at 15:36
1

Try utilizing css :after pseudo-element , content property , set attr(X) to data-* attribute set at .placeholder . Note, :before appear to be used at existing css , see touchTouch.css at lines 51-60

#gallerySlider .placeholder:after {
  content: attr(data-placeholder);
  color: yellow;
  font-size: 36px;
  font-family: arial;
  position: relative;
  display: block;
  height: 20px;
  width: 200px;
  z-Index: 1;
  bottom: 42px;
  text-align: right;
  margin: -8px;
}
<div id="gallerySlider" style="left: -400%;">
  <div class="placeholder" data-placeholder="cats">
    <img src="http://lorempixel.com/200/200/cats">
  </div>
  <div class="placeholder" data-placeholder="nature">
    <img src="http://lorempixel.com/200/200/nature">
  </div>
  <div class="placeholder" data-placeholder="animals">
    <img src="http://lorempixel.com/200/200/animals">
  </div>
</div>
guest271314
  • 1
  • 15
  • 104
  • 177
  • thanks for the reply, but my question was is how i can show the text inside the images when viewing the images on a jquery slider ? – John John Sep 03 '15 at 13:35
  • 1
    @johnG _"my question was is how i can show the text inside the images when viewing the images on a jquery slider ? "_ Yes . Could utilize `css` `:after` pseudo-element to display text over `img` element by defining `content` of parent `.placeholder` element . `img` element `content` would not render same if defined at `img:after` ; why parent element used at stacksnippets – guest271314 Sep 03 '15 at 14:22
  • 1
    @johnG Tried at `console` at link at OP http://livedemo00.template-help.com/wt_47767/index-2.html . Can create stacksnippets , jsfiddle http://jsfiddle.net including all `js` , `css` at link ? , could then apply above `css` to second image which appear after click on thumbnail image . May require minimal adjusting positioning of `:after` element , though should be able to overlay text at `data-placeholder` attribute over selected slider image . Above snippet posted to demonstrate one approach of achieving text over `img` element – guest271314 Sep 03 '15 at 14:44
  • i tried utilizing css :after pseudo-element , content .. as you mentioned and seems it is the correct approach to follow. but now in your example you mentioned this "content: attr(data-placeholder);" which will show the data-placeholder , but is there a way to modify this so the content is equal to the "" inside the "
    " in this markup :- "
    Project name:Lorem ipsum dolore massa
    "
    – John John Sep 08 '15 at 16:30
  • @johnG _"is there a way to modify this so the content is equal to the "" inside the "
    " in this markup"_ Is `span` dynamic ? or included in `html` document at page load ? Tried creating dynamic `style` element setting `content` to `span` `html` , appending to `style` element `document.body` ?
    – guest271314 Sep 09 '15 at 02:52