将段落与旋转图像一起制作动画

发布于 2024-09-08 23:34:01 字数 4087 浏览 5 评论 0原文

基本上有 4 张图像会滚动到页面之外。现在,当用户单击该链接时,该链接就会滚动消失。但我想添加一个额外的动画,其中段落(“.image_text p”)也出现在页面上,然后当单击另一个链接时,该文本将与图像的其余部分一起滚动并滚动。除了段落部分的动画之外,一切正常。

问题:

  1. 文本全部挤在一起(有四个段落,它们彼此重叠)

  2. 当我单击时- 它甚至没有时间让它消失 - 敌人在它消失之前就从页面上消失了。

  3. 第一次加载页面时,第一段甚至根本不出现 - 单击按钮时,所有段落都会出现。它应该是页面加载时出现的第一段,然后单击,然后下一段出现,因为首先随图像滚动。

标记和 CSS 是正确的。我认为问题出在这个 javascript:

      $(function() {
        $('#slideshow').crossSlide({
          sleep: 2,
          fade: 1
        }, [
          { src: '../images/img1.png' },
          { src: '../images/img2.png' },
          { src: '../images/img3.png' },
          { src: '../images/img4.png' }
        ])

                $(".paging").show();
                $(".paging a:first").addClass("active");
                $(".image_text p:first").addClass("active");


                //Get size of the image, how many images there are, then determin the size of the image reel.
                var imageWidth = $(".window").width();
                var imageSum = $(".image_reel img").size();
                var imageReelWidth = imageWidth * imageSum;

                //Adjust the image reel to its new size
                $(".image_reel").css({'width' : imageReelWidth});

                //Paging  and Slider Function
                rotate = function(){
                    $activep = $('.image_text p:first');


                    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
                    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

                    $(".paging a").removeClass('active'); //Remove all active class
                    $(".image_text p").removeClass('active'); //Remove all active class

                    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
                    $activep.addClass('active');

                    //Slider Animation
                    $(".image_reel").animate({
                        left: -image_reelPosition
                    }, 500 );

                    $(".image_text p").animate({
                        opacity: .99,
                        left: -image_reelPosition
                    }, 500 );

                }; 

                //Rotation  and Timing Event
                rotateSwitch = function(){
                    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
                        $active = $('.paging a.active').next(); //Move to the next paging
                        $activep = $('.image_text p').next(); //Move to the next paging
                        if ( $active.length === 0) { //If paging reaches the end...
                            $active = $('.paging a:first'); //go back to first
                        }
                        rotate(); //Trigger the paging and slider function
                    }, 7000); //Timer speed in milliseconds (7 seconds)
                };

                rotateSwitch(); //Run function on launch

                //On Hover
                $(".image_reel a").hover(function() {
                    clearInterval(play); //Stop the rotation
                }, function() {
                    rotateSwitch(); //Resume rotation timer
                }); 

                //On Click
                $(".paging a").click(function() {
                    $active = $(this); //Activate the clicked paging
                    //Reset Timer
                    clearInterval(play); //Stop the rotation
                    rotate(); //Trigger rotation immediately
                    rotateSwitch(); // Resume rotation timer
                    return false; //Prevent browser jump to link anchor
                });
      });

CSS for paragraph:

.image_text p {
text-align: right;
width: 500px;
opacity: 0;
position: absolute;
top: 0;
left: 0;
 }

正如蜜蜂所看到的,文本未显示的原因是因为不透明度从 0 开始。但这是有意的,因为它应该淡入。但是,它看起来它不会淡入,而是仅在单击链接时才可见,届时它会滚动出页面。

Basically there are 4 images that scroll off the page. Now when a user clicks the link, that one scrolls off. But I wanted to added an additional animation where a paragraph (".image_text p") appears on page as well and then when another link is clicked, that text goes along with rest of image and scrolls off. Everything works except the animation of the paragraph part.

The problem:

  1. The text is all squished together (there's four paragraphs and they are overlapping each other)

  2. When I click - it doesn't even have time to fade it- and foes swirving off page before it fades.

  3. First time page loads, the first paragraph doesn't even appear at all - when button is clicked, all paragraphs appear. It's supposed to be the first paragraph appears on page load and then click then the next paragraph appears as first scrolls away with image.

The markup and css are correct. I think problem is somewhere in this javascript:

      $(function() {
        $('#slideshow').crossSlide({
          sleep: 2,
          fade: 1
        }, [
          { src: '../images/img1.png' },
          { src: '../images/img2.png' },
          { src: '../images/img3.png' },
          { src: '../images/img4.png' }
        ])

                $(".paging").show();
                $(".paging a:first").addClass("active");
                $(".image_text p:first").addClass("active");


                //Get size of the image, how many images there are, then determin the size of the image reel.
                var imageWidth = $(".window").width();
                var imageSum = $(".image_reel img").size();
                var imageReelWidth = imageWidth * imageSum;

                //Adjust the image reel to its new size
                $(".image_reel").css({'width' : imageReelWidth});

                //Paging  and Slider Function
                rotate = function(){
                    $activep = $('.image_text p:first');


                    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
                    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

                    $(".paging a").removeClass('active'); //Remove all active class
                    $(".image_text p").removeClass('active'); //Remove all active class

                    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
                    $activep.addClass('active');

                    //Slider Animation
                    $(".image_reel").animate({
                        left: -image_reelPosition
                    }, 500 );

                    $(".image_text p").animate({
                        opacity: .99,
                        left: -image_reelPosition
                    }, 500 );

                }; 

                //Rotation  and Timing Event
                rotateSwitch = function(){
                    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
                        $active = $('.paging a.active').next(); //Move to the next paging
                        $activep = $('.image_text p').next(); //Move to the next paging
                        if ( $active.length === 0) { //If paging reaches the end...
                            $active = $('.paging a:first'); //go back to first
                        }
                        rotate(); //Trigger the paging and slider function
                    }, 7000); //Timer speed in milliseconds (7 seconds)
                };

                rotateSwitch(); //Run function on launch

                //On Hover
                $(".image_reel a").hover(function() {
                    clearInterval(play); //Stop the rotation
                }, function() {
                    rotateSwitch(); //Resume rotation timer
                }); 

                //On Click
                $(".paging a").click(function() {
                    $active = $(this); //Activate the clicked paging
                    //Reset Timer
                    clearInterval(play); //Stop the rotation
                    rotate(); //Trigger rotation immediately
                    rotateSwitch(); // Resume rotation timer
                    return false; //Prevent browser jump to link anchor
                });
      });

CSS for paragraph:

.image_text p {
text-align: right;
width: 500px;
opacity: 0;
position: absolute;
top: 0;
left: 0;
 }

As it can bee seen the reason why the text isn't shown is because the opacity starts at 0. But this is intended because it's supposed to fade in. However, it appears it doesn't fade in but rather only becomes visible when link is clicked and by that time it scrolls off the page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那请放手 2024-09-15 23:34:01

解决方案是指定 p 标签的数量以及容器宽度的倍数,然后使用 css 声明 overflow:hidden 指定容器,这将隐藏除当前标签之外的所有 p 标签。此外,p 标签必须向左浮动才能使它们表现得内联:

.window {
    margin-top: 20px;
    height:286px;
    width: 655px;
    overflow: hidden; 
    position: relative;
} 

.image_text  {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
}

.image_text p {
    float: left;
    margin-left: 10em;
}

The solution was to specify how may p tags and multiple that by width of container and then specifying the container with the css declaration overflow:hidden, which hides all p tags except the current. Also, p tags had to be floated left in order to get them to behave inline:

.window {
    margin-top: 20px;
    height:286px;
    width: 655px;
    overflow: hidden; 
    position: relative;
} 

.image_text  {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
}

.image_text p {
    float: left;
    margin-left: 10em;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文