简体   繁体   中英

How to Convert a linked image with rollover jquery to codeigniter

I created a html site that has images that are links, the images change on mouseover. I use a jquery function for this. It all works perfect in HTML, but Im not sure how to combine the anchor and base_url to them when converting them to codeigniter.

I have been at this all day Id really appreciate any help, I am new to codeigniter I could not find any answers on their page or with a google search.

HTML code (works fine):

<a href="hotel.html">
<img src="img/image.png" hover="img/hoverimage.png" class="rollover"/>
</a>

I can get as far as linking the src image and can apply the class=rollover I just can not figure out how to add the hover="img/hoverimage.png"

<?php echo anchor('hotel', img('img/image.png'), array('class'=>'rollover' ));?>

Finally got it working. In short, I had to put the full address of the images rather than calling the base_url within an anchor. Probably a more accurate way of doing it but I spent so much time on this I am just happy it works....

<?php echo anchor('homepg/page/hotel', '<img src="http://localhost/websitefolder/img/image1.png"  hover="http://localhost/websitefolder/img/imagehover.png" class="rollover"/>'); ?>

First, you don't need to use CodeIgniter's helpers to generate HTML. If you have working HTML already, then use it. Sometimes using CI's helpers can make the code more complicated, especially if other people need to figure out what it's doing.

To answer your question, the img() function accepts an associative array for the image's attributes. So you can specify the attributes similar to the anchor() function.

echo anchor('hotel', img(array('src' => 'img/image.png', 'class' => 'hover', 'hover' => base_url('img/hoverimage.png'))));

Note that this uses the base_url() function from the URL helper.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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