Agora que a imagem está pronta, a segunda coisa que precisamos fazer é criar um arquivo HTML simples com um link para o vídeo em que estamos criando a miniatura para:
http://vimeo.com/8736190" id=preview> Western Norway at sunrise
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
$(document).ready(function() {$('#preview').css('display', 'block').css('width', 500).css('height', 203).css('background', 'url("our-image.jpg") no-repeat');}
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
.mousemove(function(e) {var elementWidth = 500;var mousePercent = (e.pageX - this.offsetLeft) / elementWidth;var bgPosition = 0 - Math.floor((mousePercent * 5000) / elementWidth) * elementWidth;$(this).css('background-position', '-' + bgPosition + 'px 0px');});
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
demo
Next, we need to import jQuery in the head of the page: Then we use jQuery to set the display type (block) the width (500px to match the width of one 'frame' of our image) the height (203px) and the background of our link: ); Finally, we need to set the background so that the correct portion of our image is displayed; each 'frame' is 500px wide, so to show the first frame the x position of the background image should be 0px, to show the second it will be -500px, the third will be -1000px and so forth. Using a mousemove handler function, we can calculate the relative position of the cursor over the element as a percentage; we subtract the element's offset position from the event's pageX (this treats the left edge of the element as 0), then divide by the width of the element. Having done so we calculate the position of the background image by multiplying the percentage position by the total size of the composite image. We need the final result to be multiples of the element width (500px) so we divide the result by that value, round down using Math.floor(), then multiply back up to cancel out the division; if we don't do this the image will simply scroll 1px at a time. We subtract the resulting value from 0 so that all possible values are negative. Then we apply the background-position with CSS: The full script looks like this: );}); Western Norway at sunrise
Conclusão
Há algumas coisas a serem consideradas: em primeiro lugar, seria possível configurar uma miniatura com centenas de 'quadros', mas enquanto isso levaria a uma animação muito suave, também levaria muito tempo para carregar; em segundo lugar, a detecção da posição do mouse simplesmente não funcionará em um dispositivo touchscreen, portanto, embora essa técnica não prejudique a usabilidade em um dispositivo móvel, você também não está ganhando nada.
O objetivo de uma miniatura é apresentar ao usuário mais informações sobre o que está na outra extremidade de um link e, quando o recurso ao qual você está vinculando é um vídeo, uma única imagem geralmente não é suficiente. Estender a técnica do sprite CSS é uma maneira simples e eficaz de visualizar mais de um único quadro.
Como você visualiza vídeos em miniaturas? Você usa mais do que uma única imagem? Deixe-nos saber nos comentários.