简体   繁体   English

如何将图像放大到另一个位置?

[英]How to enlarge image with rollover to another position?

Hi i would like to create a image gallery where images are repositioned and resized after rollover. 嗨,我想创建一个图像库,图像在翻转后会重新定位和调整大小。 Im not sure if i have to use javascript or is just css enough. 我不确定我是否必须使用JavaScript或CSS是否足够。 I tried jQuery but i couldnt match each img with the rollovered image. 我尝试使用jQuery,但无法将每个img与翻转的图像进行匹配。 I also thought if i could give each picture different id in the php script so afterwards i can use these id-s to match rollovered image in jquery. 我还认为如果我可以给每个图片在php脚本中使用不同的id,那么以后我可以使用这些id来匹配jquery中的翻转图像。 Heres a pictures with explanation : 以下是带有说明的图片:

在此处输入图片说明

this php script generates the gallery : 这个PHP脚本生成画廊:

  function showGallery()
{
$id = 0;
$size ='';
$galleryHTML = "<ul>";
$images = new DirectoryIterator("pildid");

foreach($images as $image) {

$file = $image -> current();
$filename = $file -> getFilename();
$src = "pildid/$filename";
$info = new Finfo( FILEINFO_MIME_TYPE );
$type = $info->file($src);
$galleryhtml = "";  
if($type ==="image/jpeg" )

    $galleryhtml ="<li><img src='$src' id='' height='100px' width='120px'/></li>";
    echo $galleryhtml;


}
 $galleryhtml = "</ul>";
 include_once('view/galerii.php');


}

You will need to use javaScript to accomplish this. 您将需要使用javaScript完成此操作。

Here is a jsFiddle that will show you the image you mouseover. 这是一个jsFiddle,它将为您显示鼠标悬停的图像。

http://jsfiddle.net/Qtu9N/2/ http://jsfiddle.net/Qtu9N/2/

<style>
.preview-image {
    height: 100px;
    width: 100px;
}
#feature-image {
    height: 500px;
    width: 500px;
}
</style>


<div>
    <img class="preview-image" src="http://i1.cdnds.net/13/24/618x497/gaming-pokemon-x-and-y-artwork-3.jpg">
    <img class="preview-image" src="https://images-na.ssl-images-amazon.com/images/G/01/videogames/detail-page/pokemon.blk-wte.oshawatt.lg.jpg">
</div>
<div>
    <img id="feature-image">
</div>

<script>
$('.preview-image').on('mouseover', function (e) {
    var featureSource = e.target.src;
    //possibly transform the link here
    //your preview images should be lower quality
    //and the big image should be higher quality
    $('#feature-image').attr('src', featureSource);
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM