I'm new to Svelte and I'm trying to apply an animation to the content of my page when the user navigates to a new page. However the animation causes my entire website to duplicate during the animation.
My content looks like this:
<div class="entire-page">
<nav>
<ul>
<li> Navigation items </li>
<li> Navigation items </li>
<li> Navigation items </li>
</ul>
</nav>
<div class="content" in:slideIn out:slideOut>
Here is my first page content. This is supposed to slide in / out.
</div>
</div>
However, when the animation executes. it duplicates everything (i.e. .entire-page): This is the result in my browser until the animation is gone:
<div class="entire-page">
<nav>
<ul>
<li> Navigation items </li>
<li> Navigation items </li>
<li> Navigation items </li>
</ul>
</nav>
<div class="content" in:slideIn out:slideOut>
Here is my first page content. This is supposed to slide in / out.
</div>
</div>
<div class="entire-page">
<nav>
<ul>
<li> Navigation items </li>
<li> Navigation items </li>
<li> Navigation items </li>
</ul>
</nav>
<div class="content" in:slideIn out:slideOut>
Here is my second page content. This is supposed to slide in / out.
</div>
</div>
Is this due to some missing reference to elements?
Yes, this is to be expected.
(besides the mixup between animation and transition).
Your first page is leaving the DOM and the out:transition is triggered, this is nothing more than some fancy css that transform the element somehow, in your case some kind of slide animation. The DOM is still there until the end of this animation.
At the same time your new page is coming in, this triggers the in:transition, again just fancy css, but the DOM is there.
As you can see, logically during the in/out transition both entire pages will be present. (Almost) nothing you really can do about.
One thing you can do however is delay the in: animation with the duration of the out: one, that way the incoming page will wait for the outcoming page to have slided away. This of course only works if both pages have the same duration for the transition.
If you don't want the two pages to come one under the other, you have to wrap them in another div (that always is present) and start messing around with positioning in css. This could be used to for example have a page slide in from the right and out to the left, giving the impression that one is pushing the other out.
I had the same issue with some images i wanted to change reactively based on the page.url.pathname, my entire __layout.svelte got duplicated.
i solved it using the key directive:
<script lang="ts">
import { page } from '$app/stores';
import { fade } from 'svelte/transition';
import { colors } from '/stores';
const nav = [{ title: '/Dev', path: '/', imgUrl: '../images/dev', color: 'devBG', keyword: '/dev' }]
let keywordTitle: string;
let activeIndex: number = 0;
$: pageUrl = $page.url.pathname;
$: {
switch (pageUrl) {
case '/':
keywordTitle = nav[0].keyword;
colors.set(nav[0].color);
activeIndex = 0;
break;
}
</script>
{#each nav as cat, i}
{#key $page}
{#if activeIndex === i}
<img transition:fade src="{cat.imgUrl}-1800.jpg " />
{/if}
{/key}
{/each}
key destroys and recreate their contents when the value of an expression changes.
Docs for {#key}: https://svelte.dev/docs#key
Related
I have a simple question. Should the button, that I use to open/close my navigation menu be included in the nav tags?
The button itself is not helping in navigating but without him, there is no access to navigation.
<nav>
<ul class="nav">
<li class="nav__el nav__el-active">Home</li>
<li class="nav__el">Generic</li>
<li class="nav__el">Services</li>
<li class="nav__el">Blog</li>
<li class="nav__el">Contact</li>
</ul>
<i class="fas fa-bars"></i> //menu btn
</nav>
that's the example. Now the btn is in the nav, but it also can be like that:
<div class="topbar">
<nav>
<ul class="nav">
<li class="nav__el nav__el-active">Home</li>
<li class="nav__el">Generic</li>
<li class="nav__el">Services</li>
<li class="nav__el">Blog</li>
<li class="nav__el">Contact</li>
</ul>
</nav>
<i class="fas fa-bars"></i> //menu btn
</div>
At first glance, when reading this at WHATWG:
The nav element represents a section of a page that links to other pages or to parts within the page: a section with navigation links.
It seems to me that the button should not be included, as that's clearly not a navigation link.
Anyway, if you continue reading:
User agents (such as screen readers) that are targeted at users who can benefit from navigation information being omitted in the initial rendering, or who can benefit from navigation information being immediately available, can use this element as a way to determine what content on the page to initially skip or provide on request (or both).
With that in mind, it makes sense to include that button and any other non-link control you might have (usually in the header area) because if a screen reader user wants to...:
...skip the whole navigation, they also want to skip the other controls that are not links.
...jump straight to the navigation, they might also want to use some navigation elements that are not links.
If you check some of the examples at WHATWG, it looks like they are applying these criteria. The first example is:
<body>
<h1>The Wiki Center Of Exampland</h1>
<nav>...</nav>
<article>...</article>
...
</body>
Here, it makes sense not to skip the title on the page (to know where you are) but then skip all the navigation elements and jump straight to the content.
However, on the last one:
<nav>
<h1>Folders</h1>
<ul>
<li><a ...>... </a></li>
...
</ul>
</nav>
It would make sense to skip the Folders heading element if you are not interested in the navigation because it's actually part of it, the same way you put the heading of a section inside a section and not before it. The same applies to your menu button.
Some other examples of elements that might be part of the main navigation of the site, and thus go into <nav> are logos that link to the root of the site or search forms.
For example, LinkedIn is doing that:
Also, Bruce Lawson, who is part of the Accessibility Task Force, has the search inside the <nav> element on his personal website:
However, you can also find examples of the opposite. For example, AirBnB only includes some links in the <nav> element:
While in this case, I would have also included the search, that for me clearly represents the main way to navigate on their site.
Anyway, you could and should also use ARIA for accessibility and structured data / Schema.org markup for search engine support.
Im trying to figure out how to make my sidebars main category list clickable.
Well, it is clickable, but, when i click on any of main categories elements it does not redirect me to page i need.
Layout:
#foreach($kat as $kategorijas)
<li>
{{$kategorijas->nosaukums}} <-----here, this link doesnt respond, if i clode <li> tag here ir responds
<div>
<p><strong style="font-size: 14px">{{$kategorijas->nosaukums}}</strong></p>
<ul>
#foreach($kategorijas->apakskategorija as $apakskategorijas)
<li>{{$apakskategorijas->nosaukums}}</li> <!-- <span>({{ $kategorijas->apakskategorija->count() }})</span> -->
#endforeach
</ul>
</div>
</li>
#endforeach
But, when i clode <li>tag right after <a> tag, it works fine, but my layout changes and is not like i want it to be.
Render link, hope it is working: http://rendera.herokuapp.com/usercode/cd6e038e956c0dd390d40bee3591597c26ff464e
I'm trying to add the link to the first element of the dropdown that is "MORE" so that I could go to another page but I'm not able to do that. I have tried it many times but not able to do it.
The Code:
<li class="dropdown">More<b class="caret"></b>
<ul class="dropdown-menu">
<li>Python</li>
<li>AngularJS Framework</li>
<li>.NET Framework Development</li>
<li>Swift App Development </li>
<li class="divider"></li>
<li>Java App Development</li>
</ul>
</li>
If you need the submenu to display onclick, consider using jQuery. Or if you want the menu to appear on hover, remove the jQuery in this fiddle and uncomment the piece of CSS that will handle that. - https://jsfiddle.net/awwys0z6/1/ . Otherwise, you may have to restructure your menu like this - Show hide divs on click in HTML and CSS without jQuery
$('.dropdown').click(function() {
$('.show').toggle('.show');
});
Using jQuery
$('element').on('click', function(){
//do whatever u want
});
Using javascript
<nav>
<div onclick="linkFn()">click here</div>
</nav>
function linkFn() {
//do whatever u want
}
I want to add my navigation in the sidebar, and there isn't space for it.
I want to set it up so that when I hover over a word such as (Links) a list will appear. But I'm not sure what code I should be using to accomplish this.
An example can be seen here: http://www.colourlovers.com/ when you hover over Browse it shows a list of other links.
<div id="navigation">
<a href="http://aftermidnightworkouts.tumblr.com/tagged/healthyrecipes">Dear
Charlie</a><br>
<a href="http://aftermidnightworkouts.tumblr.com/tagged
/healthyrecipes">Portfolio</a><br>
<a href="http://aftermidnightworkouts.tumblr.com/tagged
/healthyrecipes">Aftermidnightworkouts</a><br>
<a href="http://aftermidnightworkouts.tumblr.com/tagged
/healthyrecipes">Writings</a>
</div>
Here's a little bit of code to get you started:
http://jsfiddle.net/jonigiuro/ZsAQb/
<ul id="navigation">
<li>
Dear Charlie
<ul class="subnav">
<li class="item">
subnav item1
</li>
<li class="item">
subnav item2
</li>
</ul>
</li>
</ul>
It's better to use a list for navigation menus like yours, it would be even better to wrap it in a nav tag (html5).
The trick is that you insert a child list for the subnavigation inside a list item of the main navigation and set it's css to be hidden by default. When you hover on a main navigation item you just target it's child subnavigation and display it
Just google for CSS drop down menu, lots of pages about it, you can even have it generated and then inspect the code yourself (for example here). You just need a bit of css code that use :hover selector.
I've got an unordered list that is sort of a nested javascript helpbox. You click on the help topics, and a scrollable div appears with the help items. Those help items are the unordered list.
Everything is working great in FF, Safari, IE6 (well-I am getting a horizontal scrollbar there in IE6 for some reason) and IE8. But in IE7, it is giving me one word per line and making the scrollbar verrrry loooong in order to compensate. I searched, but haven't seen yet what I'm looking for. Nothing looks obvious to me in the Developer tools in IE, but the issue is replicated there when I switch it to IE7 mode.
Thanks for any help!
Joel
Edit:
some code...
The helpbox:
<div class="helpbox">
<h2 class="title2a adjust"><a class="nodecoration" href="javascript:animatedcollapse.toggle('collapse1')">Quick Start</a></h2>
<div id="collapse1" class="helpbox2">
<ul id="helpbo">
<li class="helpchange">Add Items</li>
<li class="helpchange">Create Timeline</li>
<li class="helpchange">Set Reminder</li>
<li class="helpchange">Detailed Help Topics</li>
</ul>
<hr class="ninetypercent"></hr>
<div class="instructions helpitems" id="animators">
<div class="container"><ul>
<li>Make sure the <b>Monthly</b> tab is highlighted on the top right of the screen.</li>
<li>Click on the day that you want to add an event.</li>
<li>You can create a main event-which you can apply a timeline to, or you can create a simple to-do item.</li>
<li>Fill in the details. If you are creating a main event, you can add a timeline. If you don't know how to do that, read the <b>Create Timeline</b> help link above.</li>
<li>Click <b>Save</b> when you're done.</li>
<li>Your event or to-do will now show up in your calendar.</li>
</ul></div>
<div class="container"><ul>
<li>Click on the <b>Admin</b> tab on the top right of the screen.</li>
<li>In the main display, next to <b>Manage</b> click <b>Add Timeline</b></li>
<li>A new blank timeline template will appear.</li>
<li>Give a descriptive title of your timeline. You can always go back and edit things later if you need to.</li>
<li>The first column, <b>Days From Event</b>, is the number of days before or after the main event that you want the to-do item to happen. It must be a number-negative numbers for the days before the event and positive number for days after the event.</li>
<li>Fill in the <b>Days From Event</b>, the <b>Title</b> and <b>Description</b> of each to-do item you want to create.</li>
<li>Click <b>Add More To-Do Items</b> to add another item. Add as many items as you need.</li>
<li>If you have added <b>Team Members</b>, you can assign tasks to members in the <b>assigned to</b> column.</li>
<li>When you have finished your new timeline, click <b>Save Timeline</b>.</li>
<li>Your new timeline is now ready to be applied to your main events</li>
</ul></div>
<div class="container"><ul>
<li>You can set a reminder for a main event or a to-do item.</li>
<li>Make sure the <b>Monthly</b> tab is selected on the top right of the screen.</li>
<li>First, <b>Create or Select</b> the event that you want to set a reminder for.</li>
<li>If you have selected an existing event, click <b>Edit Event</b>.</li>
<li><b>Click</b> the <b>Checkbox</b> next to the word <b>Reminder</b>. </li>
<li>Set the date and time you'd like your reminder, and you'll get an email reminder then.</li>
</ul></div>
<div class="container"><ul>
<li>For more detailed help on specific features, please click on the <b>Help</b> tab at the top right of the screen.</li>
<li>There, you will find several <b>Tutorial Videos</b> That can walk you through more of the complex features.</li>
</ul></div>
</div>
<div class="closebutton">
close
</div>
</div>
</div>
I'm using jQuery, and the animated.collapse libraries.
js code is:
<script type="text/javascript">
//<![CDATA[
document.documentElement.className += " js"; // Add js class to the HTML element
$(function(){
var $containers = $("#animators > div").hide();
$('ul#helpbo li a').each(function(i,el){
var idx = i;
$(this).click(function(e){
var $target = $containers.filter(':eq(' + idx + ')');
// Fade out visible div
if($containers.filter(':visible').not($target).length){
$containers.filter(':visible').fadeOut(500, function(){
$target.not(':visible').fadeIn(500);
});
} else {
$target.not(':visible').fadeIn(500);
}
e.preventDefault();
})
})
});
$(".helpchange").click(function() {
$(".changinghelp").removeClass("changinghelp");
$(this).addClass("changinghelp");
});
//]]>
Another stupid noob problem. I didn't have a declared width for those inner lis. It worked fine on the other browsers because it just inherited, but not in IE7