Scrollspy using Alpinejs and intersect plugin - alpine.js

I have a website I'm working on that utilizes DaisyUI and Alpine.js (with intersect plugin).
In one of my templates I have a stepper with sections of content relating to each step. When you click one of the steps to the stepper, it scrolls you to the related section. That part is easy peasy. The difficulty is getting the step to highlight when you've scrolled to the related content manually. My lack of understanding of the intersection observer is what is throwing me off.
Here is a pen I made as a simple illustration of what I'm trying to do: https://codepen.io/jtomeck/pen/dyeVONz
The pen only shows the use of x-intersect alone. It works-ish, but you'll notice that there are bugs if you make the viewport taller. I'd ideally like the step to only highlight when the content is near the top of the screen, or at least more than halfway above the center of the viewport. I've tried:
Using threshold, but there are bugs since it does not observe the direction (from top of viewport or bottom of viewport) the intersection is happening from, as well as the threshold being defined as a percent creates strange behaviors on different sized screens.
Using margin, but it did not appear to work at all. I believe this is option is the right solution, but I'm struggling to find the proper resources online specific to my problem. I believe the answer will come if I can figure out how to manipulate the margin using enter and leave.
If someone wouldn't mind helping me with this I'd greatly appreciate it. Bonus points if all previous steps can remain highlighted when a new step is reached :). Not a requirement though!
I'd like to request that all answers continue to utilize alpinejs since it is a constraint of the project. Thank you in advance!
TLDR - Can anyone help me figure out how to use alpinejs and its intersect plugin to make the step of a stepper component highlight when the content it relates to reaches a certain position in the viewport (scrollspy effect)?
Update: Updated codepen to use:
x-intersect.margin.10%.0.0.0="shownStep = ' STEP NUMBER ID HERE '"
According to the documentation the expected behavior would be to detect intersection "when the element gets within 10% of the top of the viewport." It does not appear to work any differently than just using x-intersect without the margin added. I'm very curious why margin does seemingly nothing. I'm going to keep looking into it, but I'd very much appreciate any guidance anyone can provide about rootMargin and why the intersect plugin does not seem to be applying it properly.

Related

Problem when assigning Input.mousePosition to transform.position in Unity2D

I have been following the Inventory tutorials for Unity by Kryzarel and have encountered a weird issue that I think may be from something unrelated.
Tons of googling has yielded no results. It seems like an obscure issue.
https://www.youtube.com/channel/UCOM0GGMEcu-gyf4F1mT7A8Q/videos for reference of the channel.
But the issue I'm running into is I do the following:
draggableItem.transform.position = Input.mousePosition;
So basically draggable Item is a reference to an Image component on a GameObject. I log Input.mousePosition before hand and the values make sense (within the hundreds e.g. (563,262,0)). However, the transform position is nowhere near the number logged. For the example, I'm seeing (48660.31, 23917.95, -7889.887). There is no logic between the debug.log statement giving Input.mousePosition and the code assigning it to the transform. Anyone have any idea what I could possibly have configured wrong, or could be wrong?
I would expect the position to be (563,262,0) not the ridiculous number that it ends up being. I've tried localPosition instead of transform.position, and it sort of works. In that it's off by about 500 or 700 to the top-right of what I'm moving relative to the mouse, I want to avoid hacky solutions like subtracting some magic number if possible.
Edit: Some further background, other mouse clicks and mouse related things appear to work correctly. It's an orthographic camera, or the default for a unity2D project
Solution: IN my case I was able to set it per the accepted answer, I then had to modify position not localPosition and also had to zero out the z-value of the world point.
The mouse position is relative to your screen, not your world. You need to convert the screen space to world space with:
var pos = Camera.ScreenToWorldPoint(Input.mousePosition);

ThreeJs Side of object partially invisible

I've asked this question before, here, and the answer was to do with either using THREE.DoubleSided or recalculating the normals/switching the sides in Blender for an object which has sides that appear invisible. I have done both of these and the side that I'm using still appears partially invisible.
In Blender I deleted the outside side, selected two edges, created a new face in-between the ages and dragged it out and I got this result when rendered ThreeJS:
I've followed the advice in the accepted answer here but nothing seems to do the job.
Any other advice as to what is happening here. Thanks
EDIT
I have the side appearing now but the text that I add to the side half skews like this:
Any idea as to why this is? Boop

Autocad scaling

I'm studing AutoCAD and encountered with a scale problem.
I write a simple detail, but when i'm setting Lineweight 1.00 mm AutoCAD draw 2cm line instead of 1mm line. I tried to change scale in Annotate -> Dimensions -> Scale factor = 0.05, but it didn't help.
Here is two screenshots: how it is with and withoud LWB pressed. It does some crazy things when I want just to create a line a bit thicker than default.
I have the same problem, but this post wasn't very helpful
And this post wasn't neither
I posed it gere according to this aricle that says, that SO is the best options for this kind of questions: https://meta.stackexchange.com/questions/188052/which-stack-exchange-site-is-best-for-autocad-questions
The scale factor only controls the scale of the linetype.
To change the way the lineweight displays on the screen, right click on the "Show/Hide Lineweight" toggle at the very bottom, click "Settings..." and adjust the slider labelled "Adjust Display Scale".
Note that this will not change the printed weight of the lines, just how they show up on your monitor.
Pretty sure the Autodesk forums is the best place to ask an AutoCAD setup question.
Both posts you linked to above (Autodesk forums and AUGI) pertain to plotting and/or PaperSpace but your post is clearly showing ModelSpace.
I would check if you've drawn your sketch using polylines with a defined width. Could be a units issue as well.

Unity 4.6 - How to scale GUI elements to the right size for every resolution

The new Unity 4.6 comes with a new GUI, when I change de resolution on Unity the UI Button scales perfectly but when I test on the Nexus 7 device the Button looks too small. Any idea how to solve this?
Unity's new GUI system uses "anchors" to control how gui elements (like buttons) scale in relation to their parent container.
Unity has a tutorial video on how to use the new "Rect Transform" component (where the anchors are configured) here: http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.
The last half of the tutorial is all about anchors. That page has links to the entire tutorial series. It's not too long. You should watch the whole thing.
Specific to your question:
The anchors are visible in your first screen shot. They are those 4 little arrows at the top left of your button.
Right now, your button is only anchored by it's top left corner.
The two right anchors need to be dragged to the right so that the right edge of your button is anchored to a space inside its parent container.
Depending on your situation, the two bottom arrows may need to be dragged down so that the bottom edge of your button is anchored as well.
The video I linked above covers all this in detail.
Lastly, for the font size to scale nicely on different resolutions, you will need to add and configure a reference resolution component to the base canvas of your UI, as Ash-Bash32 wrote earlier.
Update: The best way to add a Reference Resolution component is through the inspector window for the base canvas in your UI.
1) click the "Add Component Button" at the bottom of the inspector.
2) type the word "Reference" in the search filter field.
3) select the "Reference Resolution" component in the search results.
The Reference Resolution is now renamed as Canvas Scaler.. Along with the renaming they have added many more features for the dynamicity of the Canvas. You can go through the Unity Doc of Canvas Scaler and also take a look at this article for a practical example of how and why to use Canvas Scaler. Also make sure you use the Anchor Points to good effect to make this more robust...
To Scale UI added the ReferenceResolution Component to the Canvas you want to scale.
P.S. Theres no Documention for ReferenceResolution
If you want the button to be the same size for all screens and resolutions, you have to add the canvas scaler component to the canvas and the set the screen match mode to: match width or height, here is the link to the docs, this helps a lot if you want to aim to different sizes or resolutions:
http://docs.unity3d.com/Manual/HOWTO-UIMultiResolution.html
This becomes giant and convoluted once you start laying things out in code AND using a canvas scaler, so I wish to provide a thorough answer to save someone the hours I went through.
First, don't use anchoredPosition to position anything, unless you fully realize it is a 0.0 to 1.0 number. Use the RectTransform localPosition to do the actual laying out, and remember it's in relation to the parent anchor. (I had to lay out a grid from the center)
Second, put a canvas scaler on the parent layout object AND the inner ui pieces. One makes the layout in the right position, the other will resize your elements so they actually show up right. You can't rely on the the parent unless the children also have scalers (and Graphic Raycasters to touch them).
Third, if you have a scaler, DON'T use Screen.width and height, instead assume the screen is the same value you put for the scalers (hopefully you used the same, or know what you're doing). The screen width always returns the actual device pixels, retina devices too, but the canvas scalers DO NOT account for this. This probably gives unity the one remaining way to find actual screen dpi if your game wants it. Edit: This paragraph applies to any parent canvas connected to the code doing your laying out. Not stray canvases, you can probably mix it up. Just remember unity's guidelines on performance with canvases.
Fourth, the canvas is still a bit buggy. Even with the above working, some things don't render until you delete and recreate a canvas, if you re-open the scene or it crashes. Otherwise, the above is the general "rules" I've found.
To center a "grid of things" you can't just use half of the canvas scaler's width or height, you have to calculate the height of your grid and set the offset by half of it, otherwise it will always be slightly off. I just added this as an extra tip. This calculation works for all orientations.

How to create a image and content slider in Flex?

I would like to create a image and content slider in Flex. There are many jquery plugings available
(cfr. Flexslider http://flex.madebymufffin.com/) but i can't find an alternative for Flex.
Can anyone explain me how i can implement this?
Thanks!
Ah it just so happens I already made this... a long time ago so it's Flex 3 but I believe it works as is in Flex 4, I've integrated this with other Flex 4 projects and have since made some performance improvements (mainly opting for Group over Canvas and did some deferred instantation since we decided to use it as the backbone for a pretty complex site).
http://www.shaunhusain.com/ImageSlider/
http://www.shaunhusain.com/ImageSlider/srcview/index.html
Should allow you to drag and snaps to the tile with it's top left corner nearest the top left of the container itself, also can use keyboard navigation left right up down so long as it has focus, and I made those buttons on top that can be used to trigger the movements. Basically I tried to overload that example with all possible options so I can just copy it and strip off what I don't want. It also turns out this translates pretty well to touch screens even though I didn't own one when I wrote it, the snap to nearest thing works alright on an android (even with that version which is totally not optimized for mobile). Oh yeah and you can use - and + on the keyboard or the scroll wheel to zoom, doubt if that's really ever necessary but it seemed like a cool idea at the time.

Resources