I have large, wide images within a portfolio page. The images are saved "progressive" and they load fine.
I was wondering if there's a way though to kind of preload those images to make them appearing faster and smoother. Or maybe there's a way to preload all the other pages and images into the cache so that at least all the following pages after the first appear smooth and fast? Whatever helps to make the pages load faster and smoother.
Any suggestions?
Each image consists of a variety of images, all of them within one wide image (prepared in PSD) and the visitor can shift left and right to call for the respective image to appear in the center.
Unfortunately sacrificing on the image quality or make them smaller is not an option here.
I know there are posts here on preloading images ad stuff but I can't find any that work with the image embedded in the HTML code.
Please have merci, I'm a CSS and Javascript novice, so the simpler the more likely I'll understand it. I'm afraid breaking up the images in single instances (make it a row of images instead of one whole image), place them in a floated div and change the respective Javascript code could be too challenging for me, right...? How else could I do that?
Appreciated!
Here's what I have (I guess it would be overkill to post all my HTML, Javascript and CSS here, I'll post some). The large images are placed within the HTML page and called via Javascript.
see here
<div class="ShiftGroup">
<div class="ShiftGroupC">
<div class="ShiftGroupI"><div id="ShiftGalleryFive"><img src="images/gallery_anzic1.png" width="3348" height="372" alt="imagegallery1" /></div></div>
<div class="ShiftGroupP" style="margin-left: -990px;"><div id="ShiftLeft" class="ShiftGroupD"><span class="pointer"><img src="images/arrowleft.png" width="78" height="50" alt="arrowsleft" /></span></div></div>
<div class="ShiftGroupP" style="margin-left: 341px;"><div id="ShiftRight" class="ShiftGroupD"><span class="pointer"><img src="images/arrowright.png" width="78" height="50" alt="arrowright" /></span></div></div>
and
gallery = document.getElementById('ShiftGalleryFour').style;
This is how we preloaded images in one of our projects:
preloadImages = function(imageIndex) {
// Finds div element containing index (1..n) and url of image
// (both stored as data attributes)
var image = $(".data .image[data-index=" + imageIndex + "]");
// Creates an image (just virtually) that is not embedded to HTML.
// Its source is the url of the image that is to be preloaded
var preloadedImage = $(new Image()).attr("src", image.attr("data-full-url"));
// Bind an event to the "virtual" image to start preloading next image when
// this one is done
preloadedImage.load(function() {
// Start preloading the next one
preloadImages(imageIndex + 1);
});
}
// Start preloading the first image
preloadImages(1)
In your case this solves only one part of the problem - preloading.
I see you include all images in html as img tags. If you want to achieve better performance, do not place any img tags in your html of the gallery. Just div tags that will become the future containers of your images. These divs may have indexes and contain data attributes with image urls (as seen in my example). When your page gets loaded, start preloading procedure. When an "virtual image" gets loaded. Create new image tag inside its container and start preloading the next image.
This will definitely cut off the download time of your page.
My example uses jQuery which simplifies the script. Pure javascript would be more complicated.
UPDATE:
This is how preloading example may work like.
HTML
Let's say you have 4 images and all of them has its container - a div in which individual image is to be placed.
<div class="images">
<div class="image" data-index="1" data-src="image_1_source_path"></div>
<div class="image" data-index="2" data-src="image_2_source_path"></div>
<div class="image" data-index="3" data-src="image_3_source_path"></div>
<div class="image" data-index="4" data-src="image_4_source_path"></div>
</div>
JavaScript
After the the document is loaded, preloading procedure may start. You start by preloading the first image. After this one is loaded, you append it to its container and trigger preloading of the next image. There is also return called if all images are loaded and no container is found.
preloadImages = function(imageIndex) {
var imageContainer = $(".images .image[data-index=" + imageIndex + "]");
return if imageContainer.length === 0
var preloadedImage = $(new Image()).attr("src", image.attr("data-full-url"));
preloadedImage.load(function() {
imageContainer.append(preloadedImage);
preloadImages(imageIndex + 1);
});
}
$(document).ready(function(){
preloadImages(1);
});
Hopefully you get the idea.
Related
I have an Angular component called folder-browser which serves as a folder browser. It displays the folders in a vertical list, and when a folder is opened it displays folders within that folder if there are any:
Here is the HTML for this:
<div *ngFor="let element of folders">
<div class="folder" (click)="selectFolder(element)" [ngClass]="{'selected': checkSelected(element)}">
<div class="chevron-container">
<img class="chevron-icon" src="{{getChevronIcon(element)}}">
</div>
<img class="folder-icon" src="{{folderIcon}}" />
<span class="folder-name">{{element.name}}</span>
</div>
<div class="sub-folders" *ngIf="element.expanded">
<folder-browser [folders]="element.children"></folder-browser>
</div>
</div>
My question is about the two <img> elements (there are three distinct SVGs—the chevron img element uses either a down chevron or a right chevron). As you can see, these img elements are used many times; not only are they inside an *ngFor div, this folder-browser component is used recursively to display subfolders.
The src of these img elements points to a CDN. Looking at the network tab of Chrome dev tools, I can see that each folder-browser component that is initialized makes three calls to the CDN for the three image types. Additionally, every time a folder is opened and closed (which switches the chevron between facing down and right), the down and right chevron SVGs are loaded from the CDN.
Since there are only three different SVGs being used, I would like the browser to only load each one once and then use the cached image for each subsequent img element. This seems to happen to some extent, since only one request is made per image type when the component is initialized as opposed to however many folders are in the *ngIf. However, when initializing a new instance of the same component it would be nice if it would use the cached images since they are the same.
Is there a built-in way to do this?
I'm trying to achieve the following:
I'm having simple html5 video streams running live on a website (Nr. 1-6). I would like, that the on click on one of these smaller thumbnails, that it will be displayed on top in the main bigger 'window'. I hope you understand what I mean. Is this even possible without any 3rd party tools?
That would be something like this (this example requires jQuery, just typing it out right here)
JS:
$(document).ready(function() {
$('.thumbnail').on('click',function() {
var videoSrc = $(this).attr('data-video');
$('#mainFrame').attr('src', videoSrc);
});
});
HTML parts needed:
<video id="mainFrame"></video>
<div class="thumbnail" data-video="URL_TO_VIDEO"></div>
<div class="thumbnail" data-video="URL_TO_VIDEO"></div>
This would assume you have the styling etc. already done
When I run it locally, it works fine! But it isn't working when I upload it to my host and try it out online.
here's the code I'm using:
<div class="group">
<div class="left">
<img src="img/up.png" onmouseover="this.src='img/upscroll.png'" onmouseout="this.src='img/up.png'"alt="" />
</div>
<div class="middle">
<img src="img/hobo.png" onmouseover="this.src='img/hoboscroll.png'" onmouseout="this.src='img/hobo.png'"alt="" />
</div>
<div class="right">
<img src="img/blamealcohol.png" onmouseover="this.src='img/blamealcoholscroll.png'" onmouseout="this.src='img/blamealcohol.png'"alt="" />
</div>
Ok, editing answer with a different solution altogether.
Maybe this would do what you are looking for but be a little more simple than the mouseover events.
Here's the demo http://jsfiddle.net/xxhpxd98/
<img class="clock" src="http://images.cdbaby.name/6/0/60x60music2_small.jpg" height="60px" width="60px">
<img class="briefcase" src="http://www.globetrotter1897.com/wp-content/uploads/2013/06/Burgundy-Flight-Bag-and-Small-Brief-60x60.jpg">
.clock {
position:absolute;
z-index:2;
}
.clock:hover {
opacity:0
}
.briefcase {
position:absolute;
}
If the path of the hover image is correct then the problem is something else.
Usually when a page is loaded it loads everything which is present in it in the first view. i.e it will not load any images which is put in the javascript events such as onmouseover. And the mouseover image starts loading only when you do the action (i.e mouseover). And sometime it may fail if the hover image is not cached or if the image couldn't be fetched from server.
There are different ways to solve this problem.
Here are two:
1) First method:You should preload the hover image using javascript
var image1=new Image();
image1.src="img/upscroll.png";
by this method the image upscroll.png will get cached and thus your code works fine.
2) Second method:Include all the hover images in the page and set its width and height to 1 px so that no one will see it but the image will be preloaded. If required you can change the position of these dots to fixed and keep it out of the screen at left:-10px or something like that.
This not only makes the code work fine but also it will avoid the weird appearance of the image getting loaded while mouse is over as it is already cached.
I am a newbie to html and css so sorry if this sounds dumb.
How do I create a clickable area that contains two images, text, and whitespace that when clicked, opens ANOTHER html file within the page?
So far I got an html file to appear inside an html file like this:
<object data=EXAMPLE.html width=100% height=100% /> Error </object>
But the problem with that is that you must scroll within the content box to view it, and I would prefer if it expanded the content box indefinitely downward based on how big the html file was.
As #Jarred Farrish pointed out: Regular frames do what you describe. You don't need object elements.
I believe this question becomes a duplicate of this question.
You can make a "button" by creating a div, placing the other elements within the div, and setting an onclick handler on the div itself. You are free to have as much "empty" space, because the emptiness is really the div.
<div class=my_button onclick=my_button_press();>
<img src="..."></img>
<img src="..."></img>
<span class=my_text>My text here</span>
</div>
<iframe id=my_frame></iframe>
<script>
function my_button_press() {
document.getElementById('my_iframe').src = "...";
}
</script>
Check this example http://jsfiddle.net/b6sdunqj/1/.
You'd want to combine the instruction in the question referenced above with my_button_press() to complete everything.
I have a website that is primarily used in K-12 schools. I have some social media buttons on it like Facebook 'like' and Pinterest 'pin it'. However, I'd like to have these buttons be hidden....where you have to click once on something (like an image that is covering them up but disappears when clicked....or a tab that just sort of scrolls away to reveal the buttons behind it).
The reason for this is because these sites are usually blocked in schools (I realize there's probably nothing I can do about this) and these buttons look kind of ugly when they're blocked (it'll show a question mark or or something in place of the button in these cases). However, I do want the people who do not have them blocked to be able to access and see them easily.
I am in search of a simple solution to this where the buttons wouldn't be immediately visible until you click on something.
If you're using JQuery or any other support library, you would have plenty of way to achieve your goal, even with a lot of visual effects.
Anyway, the simplest way to achieve it is by playing with the "display" attribute of the element.
Add this in your html head tag:
<script type="text/javascript>
function showElement(){
// get a reference to your element, or it's container
var myElement = document.getElementById('elementId');
myElement.style.display = '';
hideImage();
}
function hideImage(){
var myElement = document.getElementById('imageId');
myElement.style.display = 'none';
}
</script>
Now add a click event on the element you want to use to show your hidden content:
<img id="imageId" onclick="showElement()" src="..."/>
If you want to hide your "hidden" element by default, add a inline style:
<div id="elementId" style="display:none">...your buttons here...</div>
Obviously, there are a lot of better ways to achieve it (eg. changing css classes), but I think you would be able to work with the above instructions.
Edited to improve the answer:
Create an HTML structure like the following:
<div>
<img id="imageId" alt="" src="..." onclick="showElement()">
<div id="elementId" style="display:none">
<!-- your buttons, anchors or anything else you want to be hidden by default-->
</div>
</div>
So, when you click the image, the buttons appear and the image disappear.
Thanks for your help! I tried this and it works well. I think it was a pretty simple solution (even though I don't know javascript) and accomplished just what I wanted to do, which was to basically hide those buttons until an image that is covering them is clicked. Just for the record, here's the exact code I used:
<script type="text/javascript">
function showElement(){
var myElement = document.getElementById('elementId');
myElement.style.display = '';
hideImage();
}
function hideImage(){
var myElement = document.getElementById('imageId');
myElement.style.display = 'none';
}
</script>
(All I changed was adding the missing quotation mark on the first line and took out that one line about referencing to the element since I assume that is something optional.) For the html part, here's exactly what I did:
<div>
<img id="imageId" src="/images/cover.jpg" alt="cover" onclick="showElement()" width="185" height="124" />
<div id="elementId" style="display:none">
(hidden content went here)
</div>
</div>
(I didn't change much on this part either other than closing the image tag, putting in the dimensions for the image, etc.) Hopefully, I didn't do any of this wrong, but it seems to work as intended. The only other thing that would be a nice touch would be if there was a way to make it have the 'hand with pointing finger' symbol appear when you hover over it....in order to make it clear that it is a clickable image, but if not, it's not essential.