简体   繁体   English

Javascript图像替换

[英]Javascript image replacement

I have a news (blog) page where there are only ever three posts shown at a time (this is the page, how far I have now: http://thewhiteoak.fluroltd.com/our-news/ ). 我有一个新闻(博客)页面,一次只显示三个帖子(此页面是我现在所走的距离: http : //thewhiteoak.fluroltd.com/our-news/ )。 When a user clicks on a post the main header image at the top of the page will reflect the post thumbnail but a larger version (at the top of the page). 当用户单击帖子时,页面顶部的主标题图像将反映帖子缩略图,但会显示较大的缩略图(页面顶部)。

I don't want the post to go through to their own page ie single.php as there is no need for it. 我不希望该帖子进入自己的页面,即single.php,因为不需要它。 Can this be done from the generic blog page that displays the three posts? 可以通过显示三个帖子的通用博客页面完成此操作吗? The code below is what I have already which links to a larger image but not in place of the news page. 下面的代码是我已经拥有的链接到较大图像的代码,而不是新闻页面的代码。

Can anyone shed some light on this situation please. 任何人都可以对这种情况有所了解。 As I'm getting an Uncaught ReferenceError: img_paths is not defined... But I can't seem to get past this. 当我收到未捕获的ReferenceError时:img_paths尚未定义...但我似乎无法克服这一点。

This is the import for the mooTools scripts: 这是mooTools脚本的导入:

<?php  if (is_page_template('page-ournews.php')) { ?>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/moo_12.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/moo_12_more.js"></script>
<?php } ?>

The Javascript which will find the link and make it replace the current header image for the post thumbnail. 将找到链接并使其替换帖子缩略图的当前标题图像的Javascript。

<script>

window.addEvent('domready', function() {

    var images = [];
    var loadingimages = [];
    var loadingimg_path = ['images/loading-bar-black.gif'];
            loadingimg_path.each(function(im) {
                loadingimages[im] = new Element('img', {
                    'src': im,
                    'styles': {
                        'visibility': 'visible',
                        'opacity': '0',
                        'width': '961px',
                        'height': '382px',
                        'border': 'none'

                    }
                });
            });
    <?php $description = get_post_meta($post->ID, "news-image-thumb", $single = true);
        if($description !== '') {
        //echo $description;
        $pattern = '/href=(?<first>[\'|"])(?<href>[^\1]*?)(?P=first)/i';

        preg_match_all($pattern, $description, $matches);
        $descr = "'".implode("','", $matches['href'])."'";

?>
        var img_paths = [<?php echo $descr;  ?>];
        <?php
    }
    ?>

    var loader = new Asset.images(img_paths, {
        onProgress: function(counter,index) {
            loadingimages[ loadingimg_path[0] ].set('opacity','0').inject($('frame')).fade(1);

        },
        onComplete: function() {
            //fill our img array
            img_paths.each(function(im) {
                images[im] = new Element('img', {
                    'src': im,
                    'styles': {
                        'visibility': 'hidden',
                        'width': '961px',
                        'height': '382px',
                        'opacity': '0',
                        'border': 'none'

                    }
                });
            });
            //assign click events
            $$('#sidenav-content a').addEvent('click', function(e) {
                e.stop();
                $('frame').empty();

                images[this.rel].set('opacity','0').inject($('frame')).fade(1);
            });
            //show first img in frame
            $('frame').empty();
            //loadingimages[ loadingimg_path[0] ].set('opacity','0').inject($('frame')).fade(1);
            images[ img_paths[0] ].set('opacity','0').inject($('frame')).fade(1);
        }
    });

});


</script>

The code that displays the posts: 显示帖子的代码:

<div id="frame" >
    <?php $description = get_post_meta($post->ID, "news-image-large", $single = true);
        if($description !== '') {
        echo str_replace('<img ','<img width="961" height="382" id="laptopimage" ',$description);

        }?>
        </div>

        <div class="post post-page" id="post-<?php the_ID(); ?>">
            <div class="post-content our-news">
                <?php the_content(); ?>

                    <ul id="news">
                        <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("category_name=Our News&showposts=3&paged=$page"); while ( have_posts() ) : the_post(); $loopcounter++; ?>
                            <li id="postNews" class="post-<?php the_ID(); ?>">
                                <div class="box">

                                <?php 

                                        <?php if($feature_image_position == 'above'): ?>
        <?php if($enable_feature_image == 'yes' && has_post_thumbnail()): ?>
                    <!--<a href="<?php echo $large_image_url[0]; ?>" title="<?php the_title_attribute(); ?>" rel="<?php echo $rel; ?>"><?php echo theme_TIM_Thumb(317, $feature_image_height); ?></a>-->

                    <div id="sidecol">
            <div id="sidenav">
                <div id="sidenav-content">
                    <?php  if((get_post_meta($post->ID, "news-image-thumb", true))) { ?>
                            <?php echo get_post_meta($post->ID, "news-image-thumb", true); ?>       
                    <?php } ?>


                        <br/>       

                </div><!--sideanv-content-->
            </div><!--sideanv-->
        </div><!--sidecol-->




        <?php endif; ?>
    <?php endif; ?>

If I had to guess, this seems like a problem with the interaction between jQuery (which your site appears to be using already) and mooTools (which you added, if I understand correctly). 如果我不得不猜测,这似乎是jQuery(您的网站似乎已经在使用)和mooTools(如果我理解正确的话,您添加的)之间的交互问题。 You can start here: Google: mootools noconflict 您可以从这里开始: Google:mootools noconflict

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

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