Try clicking or tapping the SVG image below. If you put your pointer in the right place (the shaded path) then you should have Smashing Magazine’s homepage open in a new browser tab. If you tried to click on some white space, you might be really confused instead.
This is the dilemma I faced during a recent project that included links within SVG images. Sometimes when I clicked the image, the link worked. Other times it didn’t. Confusing, right?
I turned to the SVG specification to learn more about what might be happening and whether SVG offers a fix. The answer:
Not to be confused with DOM (Document Object Model) pointer events,
pointer-events is both a CSS property and an SVG element attribute. With it, we can manage which parts of an SVG document or element can receive events from a pointing device such as a mouse, trackpad, or finger.
A note about terminology: “pointer events” is also the name of a device-agnostic, web platform feature for user input. However, in this article — and for the purposes of the
pointer-events property — the phrase “pointer events” also includes mouse and touch events.
Outside Of The Box: SVG’s “Shape Model”
Using CSS with HTML imposes a box layout model on HTML. In the box layout model, every element generates a rectangle around its contents. That rectangle may be inline, inline-level, atomic inline-level, or block, but it’s still a rectangle with four right angles and four edges. When we add a link or an event listener to an element, the interactive area matches the dimensions of the rectangle.
Note: Adding a
clip-path to an interactive element alters its interactive bounds. In other words, if you add a hexagonal
clip-path path to an
a element, only the points within the clipping path will be clickable. Similarly, adding a skew transformation will turn rectangles into rhomboids.
SVG does not have a box layout model. You see, when an SVG document is contained by an HTML document, within a CSS layout, the root SVG element adheres to the box layout model. Its child elements do not. As a result, most CSS layout-related properties don’t apply to SVG.
So instead, SVG has what I’ll call a ‘shape model’. When we add a link or an event listener to an SVG document or element, the interactive area will not necessarily be a rectangle. SVG elements do have a bounding box. The bounding box is defined as:
the tightest fitting rectangle aligned with the axes of that element’s user coordinate system that entirely encloses it and its descendants. But initially, which parts of an SVG document are interactive depends on which parts are visible and/or painted.
Painted vs. Visible Elements
SVG elements can be “filled” but they can also be “stroked”. Fill refers to the interior of a shape. Stroke refers to its outline.
Together, “fill” and “stroke” are painting operations that render elements to the screen or page (also known as the canvas). When we talk about painted elements, we mean that the element has a fill and/or a stroke. Usually, this means the element is also visible.
However, an SVG element can be painted without being visible. This can happen if the
visible attribute value or CSS property is
hidden or when
none. The element is there and occupies theoretical space. We just can’t see it (and assistive technology may not detect it).
Perhaps more confusingly, an element can also be visible — that is, have a computed
visibility value of
visible — without being painted. This happens when elements lack both a stroke and a fill.
Note: Color values with alpha transparency (e.g.
rgba(0,0,0,0)) do not affect whether an element is painted or visible. In other words, if an element has an alpha transparent fill or stroke, it’s painted even if it can’t be seen.
Knowing when an element is painted, visible, or neither is crucial to understanding the impact of each
All Or None Or Something In Between: The Values
pointer-events is both a CSS property and an SVG element attribute. Its initial value is
auto, which means that only the painted and visible portions will receive pointer events. Most other values can be split into two groups:
- Values that require an element to be visible; and
- Values that do not.
all fall into the latter category. Their visibility-dependent counterparts —
visible — fall into the former.
The SVG 2.0 specification also defines a
bounding-box value. When the value of
bounding-box, the rectangular area around the element can also receive pointer events. As of this writing, only Chrome 65+ supports the
none is also a valid value. It prevents the element and its children from receiving any pointer events. The
pointer-events CSS property can be used with HTML elements too. But when used with HTML, only
none are valid values.
pointer-events values are better demonstrated than explained, let’s look at some demos.
Here we have a circle with a fill and a stroke applied. It’s both painted and visible. The entire circle can receive pointer events, but the area outside of the circle cannot.
Disable the fill, so that its value is
none. Now if you try to hover, click, or tap the interior of the circle, nothing happens. But if you do the same for the stroke area, pointer events are still dispatched. Changing the
fill value to
none means that this area visible, but not painted.
Let’s make a small change to our markup. We’ll add
pointer-events="visible" to our
circle element, while keeping
See the Pen How adding pointer-events: all affects interactivity by Tiffany Brown (@webinista) on CodePen.
Now the unpainted area encircled by the stroke can receive pointer events.
Augmenting The Clickable Area Of An SVG Image
Let’s return to the image from the beginning of this article. Our “amethyst” is a
path element, as opposed to a group of polygons each with a
fill. That means we can’t just add
pointer-events="all" and call it a day.
Instead, we need to augment the click area. Let’s use what we know about painted and visible elements. In the example below, I’ve added a rectangle to our image markup.
Even though this rectangle is unseen, it’s still technically visible (i.e.
visibility: visible). Its lack of a fill, however, means that it is not painted. Our image looks the same. Indeed it still works the same — clicking white space still doesn’t trigger a navigation operation. We still need to add a
pointer-events attribute to our
a element. Using the
all values will work here.
Now the entire image can receive pointer events.
bounding-box would eliminate the need for a phantom element. All points within the bounding box would receive pointer events, including the white space enclosed by the path. But again:
pointer-events="bounding-box" isn’t widely supported. Until it is, we can use unpainted elements.
pointer-events When Mixing SVG And HTML
Another case where
pointer-events may be helpful: using SVG inside of an HTML button.
In most browsers — Firefox and Internet Explorer 11 are exceptions here — the value of
event.target will be an SVG element instead of our HTML button. Let’s add
pointer-events="none" to our opening SVG tag.
See the Pen How pointer-events: none can be used with SVG and HTML by Tiffany Brown (@webinista) on CodePen.
Now when users click or tap our button, the
event.target will refer to our
function keyword instead of an arrow function and
this instead of
event.target fixes this problem. Using
SVG supports the same kind of interactivity we’re used to with HTML. We can use it to create charts that respond to clicks or taps. We can create linked areas that don’t adhere to the CSS and HTML box model. And with the addition of
pointer-events, we can improve the way our SVG documents behave in response to user interaction.
Browser support for SVG
pointer-events is robust. Every browser that supports SVG supports the property for SVG documents and elements. When used with HTML elements, support is slightly less robust. It isn’t available in Internet Explorer 10 or its predecessors, or any version of Opera Mini.
We’ve just scratched the surface of
pointer-events in this piece. For a more in-depth, technical treatment, read through the SVG Specification. MDN (Mozilla Developer Network) Web Docs offers more web developer-friendly documentation for
pointer-events, complete with examples.
(rb, ra, yk, il)
Link to original:
In 2018, video marketing has become ubiquitous in news feeds and it’s one of the best tools for persuasion you have available to you. In fact, 72% of businesses say video has improved their conversion rates. Naturally, because your landing pages are designed to persuade and convert, it makes total sense you’d want to use videos to boost the power of your offer.
But how do you know if visitors are actually interacting with your landing page videos? If you’re spending money on producing video content (especially if it’s offer-specific), you’ll want to know if your target audience is engaging.
While some of you may have access to a video marketing platform and resulting analytics, this post is going to share how you can get view information for YouTube video players using the free tool Google Tag Manager.
Once you follow the steps below for your Unbounce pages, you’ll be able to see:
- If visitors are actually watching the videos on your landing pages
- The duration of how long visitors are watching for, and
- Where visitors are dropping off (this can help you understand what content to modify to keep visitors engaged).
First up: Add Google Tag Manager to Track Your Landing Page Videos
This is really easy to do in Unbounce. First:
- Head to the Script Manager under your Settings tab.
- Then, click the green “Add a Script” button.
- Next, select the Google Tag Manager option.
- Assuming you’ve already signed up for Google Tag Manager, you can add your Container ID.
Lastly, attach your domain to the script, and you’re all set!
Once you have the script saved, use Google Tag Assistant to confirm the tag is working. After setting up this Tag Manager, next we’ll want to define how we want to track user interactions with our YouTube embeds, which brings us to…
Create Tags to Track Video Engagement
On September 12, 2017, Google Tag Manager released the YouTube Video Trigger which finally gave marketers the opportunity to track engagement from embedded YouTube videos within Google Analytics. Tag Manager added built-in video variables, and we want to confirm they are selected before creating any tags or triggers.
When you get to the Variables page in Google Tag Manager:
- click on the red Configure button, and simply check the boxes for all the video variables, as seen in the image below:
Next, we can create our trigger. Triggers control how the tag will be fired. The only option we need is the YouTube Video trigger type.
From here you can select the specific information you want to capture. These actions include when a user starts a video, completes a video, pause/seeking/buffering, and the duration of how much of the content they actually watch.
In the image above, we see just one option of a trigger you can create. If you choose to select ‘Progress’, you have to choose either Percentages or Time Thresholds. It has to be one or the other. You can’t do both. Using Percentages, you can add any number you like (i.e. it doesn’t have to be the numbers I used in the example above). Tag Manager will automatically add 100 for a completion.
On the other hand, if you choose ‘Time thresholds’, you will add the numbers (in seconds) you’d like to have recorded in Google Analytics. If your campaign focus is on views, I’d stick with Percentages. But, if you want to see where users are dropping off to help you improve the content of your videos, Time Thresholds is a good choice.
Lastly, choose when the trigger will fire. By default Tag Manager will fire the trigger on all videos, but you can choose to fire on only some videos.
You can also make your video triggers a lot more specific. The image below shows several options you have to fire the tag on a variety of custom variables for your YouTube videos. If you only want to track videos on certain landing pages, you can do that, but if you only want to track certain videos no matter what the landing page is, you have that option too. Create the trigger which will give you the data you need to make better decisions about the videos on your landing pages.
Now let’s set up the tag!
The image below is just one example of a completed tag set up. Here, you can change the Category, Action, and Label to capture the appropriate video data you want to collect. You can also research and find some cool custom versions of these tags like Simo Ahava’s YouTube Video Trigger. There are many options out there, so find the tag which works best for you.
Now that we can track the YouTube video interactions, let’s view the data.
View the Events Report in Google Analytics
In Google Analytics, head over to Behavior > Events. In the Overview or Top Events sections, you can see the Event Category lists of whatever you are tracking. While Event Category is the default view, you can switch to Event Action or Event Label to get deeper data depending on how you set up your tag.
So, how do you relate YouTube video tracking with our landing pages? Easy. Click on Secondary dimension, search for “landing pages” and select it. From here you’ll be able to see the page URL path alongside the current view you have pulled up.
We now have the data in Google Analytics to view which videos users interact with the most, how long are users watching the embedded YouTube videos, and which landing pages are actually seeing video engagement.
Now You Have Data to Improve the Videos on Your Landing Pages
If you find visitors barely watch your videos (think viewing less than 30% of the content), you now have data to push your team to modify the length of the videos, for example, or get to your key message differently (perhaps you have a really long intro?).
If the data shows users aren’t watching your videos at all, you may want to replace the video on your landing page with other, more customized options, or even text that sums up the value props presented. Finally, if you identify really popular videos, it could be a great opportunity to determine if there are opportunities for reuse on other relevant pages, too.
Overall, you won’t know whether page visitors resonate with the videos on your landing pages unless you track this. Let me know in the comments below if you have any questions on the setup above – happy to jump in with answers.
When building a web application, one must consider what kind of delivery mechanism they are going to use. Let’s say we have a cross-platform application that works with real-time data; a stock market application providing ability to buy or sell stock in real time. This application is composed of widgets that bring different value to the different users.
When it comes to data delivery from the server to the client, we are limited to two general approaches: client pull or server push.
See original article –
(This is a sponsored article.) Everybody’s talking about design systems, but they are more than just a trend. They are a best practice for design consistency and efficiency between designers and developers.
Back in the day, only large companies could afford the effort of building and maintaining a design system. Nowadays, with the growth of new tools and processes, they have become much more feasible for companies of all sizes.
Continue at source:
We love exploring opportunities. While many of us are quite familiar with publications and events surrounding us, we often lack the global perspective on what’s happening in the web industry across the world. For example, do you know what the state of web design in Singapore is? What about front-end events in Kuala Lumpur? What about the acceptance of UX-driven processes in Hong Kong? That’s exactly what we want to find out!
Link to article:
Design doesn’t scale as cleanly as engineering. It’s not enough that each element and page is consistent with each other — the much bigger challenge lies in keeping the sum of the parts intact, too. And accomplishing that with a lot of designers involved in the same project.
If you’re working in a growing startup or a large corporation, you probably know the issues that come with this: The big-picture falls from view easily as everyone is focusing on the details they are responsible for, and conceptions about the vision of the design might be interpreted differently, too.
In case you hadn’t noticed – though I’m guessing you have – consumption of online video has been steadily rising in recent years. According to a forecast by Cisco, video will represent 80% percent of all consumer-based internet traffic by 2019. In the information age, the average person has a shorter attention span than a goldfish, and unless your content is extra special, people are unlikely to pay attention. A compelling video stands out from generic mass marketing and communicates your message more impactfully than text-based content. In terms of generating engagement, text-based content simply can’t compete with sensory-rich, emotive…
See the original article here:
If you’re only going to use one social media site for marketing, the chances are it’s going to be Facebook. The now-ubiquitous social networking site has come a long way since its Harvard University origins and has been open to the public since September 2006. Over the years, it has added features that have become synonymous with social media as a whole, including photo sharing, video sharing, messaging and live video. It has also become a platform for other apps and games, has acquired other popular social and messaging networks (most notably Instagram and WhatsApp) and includes advertising. Facebook by…
Editor’s note: So you’ve attended a conference, listened to some truly inspiring talks, made quite a few valuable connections, maybe even attended a hands-on workshop and learned a thing or two. What now? How do you bring back the new knowledge and ideas and connections to your team and to your work? This article highlights a practical strategy of getting there without much effort. With SmashingConf Barcelona taking place next week, we thought this article would come in handy.
Have you ever been to a conference with top speakers, awesome people to network with and such a great energy that you got fired up and couldn’t wait to get home to start applying everything you’ve learned? How do things look two weeks later? Did you implement all of that learning into action? How about two months later? Were you still taking action on that knowledge?
The post How To Transform Your Next Conference Takeaways Into Real-Life Results appeared first on Smashing Magazine.